C++: Static variables in multithreaded program

Initialization is not thread-safe. Two threads can enter the function and both may initialize the function-scope static variable. That’s not good. There’s no telling what the result might be.

In C++0x, initialization of function-scope static variables will be thread-safe; the first thread to call the function will initialize the variable and any other threads calling that function will need to block until that initialization is complete.

I don’t think there are currently any compiler + standard library pairs that fully implement the C++0x concurrency memory model and the thread support and atomics libraries.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)