Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
a95da770
Commit
a95da770
authored
7 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
threadpool_clean now stops the threads, cleans up the barriers, and de-allocates memory correctly.
parent
cc56be0d
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!385
Threadpool task plots2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/threadpool.c
+20
-0
20 additions, 0 deletions
src/threadpool.c
with
20 additions
and
0 deletions
src/threadpool.c
+
20
−
0
View file @
a95da770
...
...
@@ -174,6 +174,10 @@ void *threadpool_runner(void *data) {
/* Wait for the controller. */
pthread_barrier_wait
(
&
tp
->
run_barrier
);
/* If no map function is specified, just die. We use this as a mechanism
to shut down threads without leaving the barriers in an invalid state. */
if
(
tp
->
map_function
==
NULL
)
pthread_exit
(
NULL
);
/* Do actual work. */
threadpool_chomp
(
tp
,
atomic_inc
(
&
tp
->
num_threads_running
));
}
...
...
@@ -310,6 +314,22 @@ void threadpool_reset_log(struct threadpool *tp) {
* @brief Frees up the memory allocated for this #threadpool.
*/
void
threadpool_clean
(
struct
threadpool
*
tp
)
{
/* Destroy the runner threads by calling them with a NULL mapper function
and waiting for all the threads to terminate. This ensures that no thread
is still waiting at a barrier. */
tp
->
map_function
=
NULL
;
pthread_barrier_wait
(
&
tp
->
run_barrier
);
for
(
int
k
=
0
;
k
<
tp
->
num_threads
-
1
;
k
++
)
{
void
*
retval
;
pthread_join
(
tp
->
threads
[
k
],
&
retval
);
}
/* Release the barriers. */
if
(
pthread_barrier_destroy
(
&
tp
->
wait_barrier
)
!=
0
||
pthread_barrier_destroy
(
&
tp
->
run_barrier
)
!=
0
)
error
(
"Failed to destory threadpool barriers."
);
/* Clean up memory. */
free
(
tp
->
threads
);
#ifdef SWIFT_DEBUG_THREADPOOL
for
(
int
k
=
0
;
k
<
tp
->
num_threads
;
k
++
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment