Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
Takin
tlibs
Commits
9423f21f
Commit
9423f21f
authored
Apr 08, 2020
by
Tobias WEBER
Browse files
updated threading
parent
44d712f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
helper/thread.h
View file @
9423f21f
...
...
@@ -36,7 +36,7 @@ class ThreadPool
protected:
boost
::
asio
::
thread_pool
m_tp
;
std
::
mutex
m_mtx
;
std
::
mutex
m_mtx
,
m_mtxStart
;
// list of wrapped function to be executed
t_task
m_lstTasks
;
...
...
@@ -44,6 +44,7 @@ class ThreadPool
// futures with function return values
t_fut
m_lstFutures
;
// function to run before each thread (not task)
void
(
*
m_pThStartFunc
)()
=
nullptr
;
...
...
@@ -76,8 +77,18 @@ class ThreadPool
boost
::
asio
::
post
(
m_tp
,
[
this
,
thetask
]()
->
void
{
if
(
m_pThStartFunc
)
(
*
m_pThStartFunc
)();
{
// ensure that this is only called per-thread, not per-task
std
::
lock_guard
<
std
::
mutex
>
lockStart
(
m_mtxStart
);
thread_local
bool
bThreadAlreadySeen
{
0
};
if
(
m_pThStartFunc
&&
!
bThreadAlreadySeen
)
{
bThreadAlreadySeen
=
1
;
(
*
m_pThStartFunc
)();
}
}
(
*
thetask
)();
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment