• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Reordering of Instructions in a Threaded Context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Bug: XCode fails to debug Adobe CS2 apps
  • Next by Date: Re: "distccsched" eating cpu, running hot
  • Previous by thread: Re: Bug: XCode fails to debug Adobe CS2 apps
  • Next by thread: problem with c code.
  • Index(es):
    • Date
    • Thread