]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/tutorial/tss.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / tutorial / tss.cpp
1 // Copyright (C) 2001-2003
2 // William E. Kempf
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/thread/thread.hpp>
8 #include <boost/thread/tss.hpp>
9 #include <cassert>
10
11 boost::thread_specific_ptr<int> value;
12
13 void increment()
14 {
15 int* p = value.get();
16 ++*p;
17 }
18
19 void thread_proc()
20 {
21 value.reset(new int(0)); // initialize the thread's storage
22 for (int i=0; i<10; ++i)
23 {
24 increment();
25 int* p = value.get();
26 assert(*p == i+1);
27 }
28 }
29
30 int main(int argc, char* argv[])
31 {
32 boost::thread_group threads;
33 for (int i=0; i<5; ++i)
34 threads.create_thread(&thread_proc);
35 threads.join_all();
36 }