Reordering of Instructions in a Threaded Context
Reordering of Instructions in a Threaded Context
- Subject: Reordering of Instructions in a Threaded Context
- From: Andreas Grosam <email@hidden>
- Date: Mon, 28 Feb 2005 10:19:22 +0100
This is a general C++ question, hopefully not too OT ;-)
While implementing a thread savvy Singleton pattern, this question came up:
Suppose the following source lines:
Foo* p = 0;
p = new Foo();
Is it guaranteed that - in any case (e.g. inlined c-tors, aggressive optimization) - the variable p will be assigned with the result *after* the object has been completely initialized?
Or, may p be set after the memory has been successfully allocated but *before* the initialization of the object has been finished (due to reordering of instructions from the compiler)?
If so, would declaring p as a volatile pointer help?
Foo* volatile p = 0;
Regards
Andreas Grosam
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden