Thread: Using atomic types

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    15

    Using atomic types

    In C is equivalent to use atomic types without calling atomic_load, atomic_store or atomic_fetch_add but using the standard C syntax of non atomic variables.

    These 2 pieces of codes are really equivalent and portable?
    With atomic functions:
    Code:
    atomic_int var;
    atomic_store(&var,10);
    if (atomic_load(&var))
    {
    ...
    }
    atomic_fetch_add(&var,1);
    atomic_fetch_add(&var,10);
    With standard syntax:
    Code:
    atomic_int var;
    var=10;
    if (var)
    {
    ...
    }
    var++;
    var+=10;
    I've tried with compiler explorer and seemed the same but I want to be sure that the standard syntax is equivalent in calling the relative atomic functions and it is portable.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    In compiler explorer, are you compiling as C or C++?
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Mar 2020
    Posts
    15
    I have tried in C. In C++ is of course the same because there are the operators overloading

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    In C, the code is different for me.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. helgrind shows race conditions with atomic types
    By hebrerillo in forum C++ Programming
    Replies: 5
    Last Post: 01-02-2018, 02:44 AM
  2. is SetSystemTime atomic?
    By bling in forum Windows Programming
    Replies: 1
    Last Post: 09-24-2008, 01:02 PM
  3. Atomic Operations
    By Elysia in forum Windows Programming
    Replies: 27
    Last Post: 03-27-2008, 02:38 AM
  4. Atomic Types
    By miclus in forum C++ Programming
    Replies: 4
    Last Post: 01-01-2004, 08:39 PM
  5. Atomic instructions
    By Roaring_Tiger in forum C Programming
    Replies: 1
    Last Post: 04-29-2003, 09:00 PM

Tags for this Thread