Ticket #1168: tss_bug.cpp

File tss_bug.cpp, 451 bytes (added by t_schwinger, 15 years ago)

Attempt of minimal reconstruction of the problem. Could crash it in a batch loop - crash too unlikely for debugging

Line 
1#include <cassert>
2#include <boost/thread.hpp>
3
4boost::thread_specific_ptr<int> tsp;
5
6void thread()
7{
8 if (tsp.get() == 0l) tsp.reset(new int);
9
10 for(int i = 0; i < 10000; ++i)
11 {
12 unsigned cnt = ++*tsp;
13 boost::thread::yield();
14 assert(cnt == *tsp);
15 }
16}
17
18int main()
19{
20 boost::thread_group threads;
21 for (int i = 0; i < 30; ++i)
22 threads.create_thread(& thread);
23 threads.join_all();
24
25 return 0;
26}