#include #include boost::thread_specific_ptr tsp; void thread() { if (tsp.get() == 0l) tsp.reset(new int); for(int i = 0; i < 10000; ++i) { unsigned cnt = ++*tsp; boost::thread::yield(); assert(cnt == *tsp); } } int main() { boost::thread_group threads; for (int i = 0; i < 30; ++i) threads.create_thread(& thread); threads.join_all(); return 0; }