Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > POD function st...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 4070 of 4146
Post > Topic >>

POD function static initialization from function return, thread safe?

by Brian Cole <coleb2@[EMAIL PROTECTED] > Oct 4, 2008 at 02:50 PM

I know from previous posts on this list that function static
initialization is not thread safe. But in the case of initializing
plain old data (POD) from a re-entrant function that will return the
same value every time, the race condition appears to be
inconsequential. The assumption appears to be that POD assignment is
atomic, isn't this true on all major platforms?

For example:
unsigned int Bar(); // a threadsafe function that always returns the
same value
void Foo()
{
  static unsigned int bar = Bar();
  // go on to make use of bar
}

Is this assumption safe? Where is it not? Or am I just playing with
fire and asking to get burned?

Thanks,
Brian
 




 3 Posts in Topic:
POD function static initialization from function return, thread
Brian Cole <coleb2@[EM  2008-10-04 14:50:23 
Re: POD function static initialization from function return, thr
David Schwartz <davids  2008-10-06 04:57:25 
Re: POD function static initialization from function return, thr
Anthony Williams <anth  2008-10-06 14:19:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 8:02:57 CST 2008.