FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
thread/example/thread_group.cpp at develop · boostorg/thread · GitHub
boostorg
/
thread
Public
Notifications
You must be signed in to change notification settings
Fork
171
Star
213
Code
Issues
77
Pull requests
13
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
thread
/
example
/
thread_group.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (66 loc) · 1.76 KB
Breadcrumbs
thread
/
example
/
thread_group.cpp
Copy path
File metadata and controls
72 lines (66 loc) · 1.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
Copyright (C) 2001-2003
//
William E. Kempf
//
//
Distributed under the Boost Software License, Version 1.0. (See accompanying
//
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
include
<
boost/thread/thread.hpp
>
#
include
<
iostream
>
#
include
<
boost/detail/lightweight_test.hpp
>
int
g_count =
0
;
boost::mutex g_mutex;
void
increment_count
()
{
boost::unique_lock<boost::mutex>
lock
(g_mutex);
std::cout <<
"
count =
"
<< ++g_count << std::endl;
}
boost::thread_group g_threads2;
void
increment_count_2
()
{
boost::unique_lock<boost::mutex>
lock
(g_mutex);
BOOST_TEST
(g_threads2.
is_this_thread_in
());
std::cout <<
"
count =
"
<< ++g_count << std::endl;
}
int
main
()
{
{
boost::thread_group threads;
for
(
int
i =
0
; i <
3
; ++i)
threads.
create_thread
(&increment_count);
threads.
join_all
();
}
#
if
defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
{
boost::thread_group threads;
for
(
int
i =
0
; i <
3
; ++i)
threads.
create_thread
(&increment_count);
threads.
interrupt_all
();
threads.
join_all
();
}
#
endif
{
boost::thread_group threads;
boost::thread* th =
new
boost::thread
(&increment_count);
threads.
add_thread
(th);
BOOST_TEST
(! threads.
is_this_thread_in
());
threads.
join_all
();
}
{
boost::thread_group threads;
boost::thread* th =
new
boost::thread
(&increment_count);
threads.
add_thread
(th);
BOOST_TEST
(threads.
is_thread_in
(th));
threads.
remove_thread
(th);
BOOST_TEST
(! threads.
is_thread_in
(th));
th->
join
();
delete
th;
}
{
{
boost::unique_lock<boost::mutex>
lock
(g_mutex);
boost::thread* th2 =
new
boost::thread
(&increment_count_2);
g_threads2.
add_thread
(th2);
}
g_threads2.
join_all
();
}
return
boost::report_errors
();
}
Back
|
FazBrowse Home
|
New Git URL