Ticket #1168: tss_bug.cpp
| File tss_bug.cpp, 451 bytes (added by , 15 years ago) |
|---|
| Line | |
|---|---|
| 1 | #include <cassert> |
| 2 | #include <boost/thread.hpp> |
| 3 | |
| 4 | boost::thread_specific_ptr<int> tsp; |
| 5 | |
| 6 | void 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 | |
| 18 | int 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 | } |
