just::thread Support Forum

General Category => General Discussion about just::thread => Topic started by: TA on February 17, 2011, 03:22:57 PM

Title: ATOMIC_VAR_INIT
Post by: TA 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?
Title: Re: ATOMIC_VAR_INIT
Post by: Anthony Williams 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++.
Title: Re: ATOMIC_VAR_INIT
Post by: TA on February 17, 2011, 03:38:49 PM
Got it. Thanks.