Last change
on this file since 45 was
29,
checked in by landauf, 17 years ago
|
updated boost from 1_33_1 to 1_34_1
|
File size:
766 bytes
|
Line | |
---|
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 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.