static boost::barrier - do I need a mutex here ?

Hi, Just a short question: Do you think I need a mutex for the 'static boost::barrier(nThreads)' lines in the sample code snippet below ? I always thought that static data in a function has to be protected by a mutex. But even with 16 running threads in parallel everything seems to be fine (it's a machine with 8 hardware cores, no HT). Thanks in advance - Hans int nThreads; // initialized later in main() void testing() { static boost::barrier barrier_one(nThreads); // mutex needed for 'local static' ? log("waiting on barrier_one"); barrier_one.wait(); do_complicated_stuff_simulaneously(); log("passed barrier_one"); static boost::barrier barrier_two(nThreads); // mutex needed for 'local static' ? log("waiting on barrier_two"); barrier_two.wait(); do_more_complicated_stuff_simulaneously(); log("passed barrier_two"); }

Vokuba wrote:
Just a short question: Do you think I need a mutex for the 'static boost::barrier(nThreads)' lines in the sample code snippet below ? I always thought that static data in a function has to be protected by a mutex.
For some years gcc has been protecting function-scope statics with a mutex by default. You can change this with -fno-threadsafe-statics. I'm unsure what other compilers do and what the standards require (though I did know at one time!). Regards, Phil.
participants (2)
-
Phil Endecott
-
Vokuba