Thread: Atomic operations

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    Atomic operations

    Hi,

    I'm reading some of the C++ working standard, and I arrive at the chapter on Atomic Operations Library.

    Are these types/operations which will never be split over various threads, i.e., thread-safe types and operations?

    If that's true, why are there types like "atomic_bool" ? A normal primitive 'bool' is already type safe?

    Further, could someone explain me some of the applications? Massive parallel for example?


    Thanks for your explications!!!


    Mark

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Being type-safe and thread-safe are completely different concepts.

    > Further, could someone explain me some of the applications?
    Anything involving threads.
    On a single CPU, the granularity is a single instruction.
    On a multi-CPU system, the granularity is a bus cycle.

    What the atomic types guarantee is that the objects will still do the right thing, despite the increased opportunity for interleaving the actions of multiple CPUs.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Salem View Post
    On a single CPU, the granularity is a single instruction.
    That's no longer true with multi-core CPUs.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'd say that "single CPU" means "Single core" - Multi-CPU systems are those with more than one processing unit, no matter if that is provided through a single chip or multiple chips.

    Note that for example a single-core CPU with an "intelligent"[1] graphics processor, is also a "multiprocessor" system. Although it is of course only relevant for data shared between the CPU and the GPU.

    [1] Literally anything more advanced than the VGA graphics adapters, and certainly ALL of the 3D graphics cards are "intelligent" in this context.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Atomic integers & memcpy()
    By rasta_freak in forum C Programming
    Replies: 11
    Last Post: 08-05-2008, 12:08 PM
  2. Atomic Operations
    By Elysia in forum Windows Programming
    Replies: 27
    Last Post: 03-27-2008, 02:38 AM
  3. doing floating operations using integer operations
    By ammalik in forum C Programming
    Replies: 10
    Last Post: 08-15-2006, 04:30 AM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM