FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
thread/example/this_executor.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
/
this_executor.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (67 loc) · 2.07 KB
Breadcrumbs
thread
/
example
/
this_executor.cpp
Copy path
File metadata and controls
85 lines (67 loc) · 2.07 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
73
74
75
76
77
78
79
80
81
82
83
84
85
//
Copyright (C) 2014 Vicente Botet
//
//
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/config.hpp
>
#
if
! defined BOOST_NO_CXX11_DECLTYPE
#
define
BOOST_RESULT_OF_USE_DECLTYPE
#
endif
#
define
BOOST_THREAD_VERSION
5
#
define
BOOST_THREAD_USES_LOG_THREAD_ID
#
include
<
boost/thread/caller_context.hpp
>
#
include
<
boost/thread/executors/basic_thread_pool.hpp
>
#
include
<
boost/thread/executors/generic_executor_ref.hpp
>
#
include
<
boost/smart_ptr/shared_ptr.hpp
>
#
include
<
boost/smart_ptr/make_shared.hpp
>
#
include
<
string
>
#
include
<
iostream
>
#
include
<
boost/thread/caller_context.hpp
>
struct
current_executor_state_type
{
boost::shared_ptr<boost::generic_executor_ref> current_executor_ptr;
template
<
class
Executor
>
void
set_current_executor
(Executor& ex)
{
current_executor_ptr = boost::make_shared<boost::generic_executor_ref>(ex);
}
boost::generic_executor_ref
current_executor
()
{
if
(current_executor_ptr)
return
*current_executor_ptr;
else
throw
"
"
;
}
};
thread_local
current_executor_state_type current_executor_state;
boost::generic_executor_ref
current_executor
()
{
return
current_executor_state.
current_executor
();
}
void
p2
()
{
std::cout <<
BOOST_CONTEXTOF
<< std::endl;
boost::this_thread::sleep_for
(
boost::chrono::milliseconds
(
200
));
std::cout <<
BOOST_CONTEXTOF
<< std::endl;
}
void
p1
()
{
std::cout <<
BOOST_CONTEXTOF
<< std::endl;
boost::this_thread::sleep_for
(
boost::chrono::milliseconds
(
200
));
current_executor
().
submit
(&p2);
boost::this_thread::sleep_for
(
boost::chrono::milliseconds
(
400
));
std::cout <<
BOOST_CONTEXTOF
<< std::endl;
}
int
main
()
{
std::cout <<
BOOST_CONTEXTOF
<< std::endl;
boost::basic_thread_pool
tp
(
4
,
//
at_thread_entry
[](boost::basic_thread_pool& pool)
{
current_executor_state.
set_current_executor
(pool);
}
);
tp.
submit
(&p1);
boost::this_thread::sleep_for
(
boost::chrono::seconds
(
5
));
std::cout <<
BOOST_CONTEXTOF
<< std::endl;
return
1
;
}
Back
|
FazBrowse Home
|
New Git URL