Author Topic: ATOMIC_VAR_INIT  (Read 60041 times)

TA

  • Newbie
  • *
  • Posts: 20
    • View Profile
ATOMIC_VAR_INIT
« on: February 17, 2011, 03:22:57 PM »
Anthony,

Could you please explain what ATOMIC_VAR_INIT is used for? I couldn't find any useful information on that (or maybe I just coulnd't get it). As far as I understood it is used to initialize atomic variables in some special way, but what kind of initialization is done? When it might be useful? All the examples I could find was
atomic<int> t = ATOMIC_VAR_INIT(2);
why not just
atomic<int> t = 2;
what's the difference?

Anthony Williams

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
    • just::thread C++ Thread Library
Re: ATOMIC_VAR_INIT
« Reply #1 on: February 17, 2011, 03:35:58 PM »
Could you please explain what ATOMIC_VAR_INIT is used for? I couldn't find any useful information on that (or maybe I just coulnd't get it). As far as I understood it is used to initialize atomic variables in some special way, but what kind of initialization is done? When it might be useful? All the examples I could find was
atomic<int> t = ATOMIC_VAR_INIT(2);
why not just
atomic<int> t = 2;
what's the difference?

ATOMIC_VAR_INIT is there for C compatibility, since you can't write
Code: [Select]
atomic_int i(3);
in C, but you can write
Code: [Select]
atomic_int i=ATOMIC_VAR_INIT(3);
in both C and C++.

TA

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: ATOMIC_VAR_INIT
« Reply #2 on: February 17, 2011, 03:38:49 PM »
Got it. Thanks.