General Category > General Discussion about just::thread

ATOMIC_VAR_INIT

(1/1)

TA:
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:

--- Quote from: TA on February 17, 2011, 03:22:57 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?

--- End quote ---

ATOMIC_VAR_INIT is there for C compatibility, since you can't write

--- Code: ---atomic_int i(3);

--- End code ---
in C, but you can write

--- Code: ---atomic_int i=ATOMIC_VAR_INIT(3);

--- End code ---
in both C and C++.

TA:
Got it. Thanks.

Navigation

[0] Message Index

Go to full version