Jorge Moraleda
I must be doing something wrong, but I can't figure out what. I would appreciate some help. Thank you in advance.
The following program:
#include
void threadEntry() { }
int main (int argc, char *argv[]) { for(size_t t=0; t<10; t++) { boost::thread(threadEntry); } }
runs cleanly with valgrind drd, but this other program produces race conditions when run with valgrind drd (see below). The only difference is "new".
#include
void threadEntry() { }
int main (int argc, char *argv[]) { for(size_t t=0; t<10; t++) { new boost::thread(threadEntry); } }
I don't know why the result is different. Maybe the result is different because the compiler optimizes the code differently. Anyway, it looks like the detected race is in call_once. The code there relies on the fact that reading and writing integers is atomic, so you'll never get a part-updated value, even if the value read is stale. This is technically a race, but works on common platforms. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976