Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QuickSched
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
QuickSched
Commits
cc5c103e
Commit
cc5c103e
authored
10 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug that caused segfaults when freeing pthreads.
parent
7b7b3e70
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/qsched.c
+30
-1
30 additions, 1 deletion
src/qsched.c
with
30 additions
and
1 deletion
src/qsched.c
+
30
−
1
View file @
cc5c103e
...
...
@@ -410,12 +410,15 @@ void *qsched_pthread_run ( void *in ) {
struct
qsched
*
s
=
r
->
s
;
int
tid
=
r
->
tid
;
struct
task
*
t
;
/* Main loop. */
while
(
1
)
{
/* Wait at the barrier. */
qsched_barrier_wait
(
s
,
tid
);
/* If there is no function to execute, then just quit. */
if
(
s
->
fun
==
NULL
)
pthread_exit
(
NULL
);
/* Loop as long as there are tasks. */
while
(
(
t
=
qsched_gettask
(
s
,
tid
)
)
!=
NULL
)
{
...
...
@@ -477,6 +480,7 @@ void qsched_run_pthread ( struct qsched *s , int nr_threads , qsched_funtype fun
s
->
runners
[
tid
].
s
=
s
;
if
(
pthread_create
(
&
s
->
runners
[
tid
].
thread
,
NULL
,
qsched_pthread_run
,
(
void
*
)
&
s
->
runners
[
tid
]
)
!=
0
)
error
(
"Failed to create pthread."
);
s
->
runners_count
+=
1
;
}
}
...
...
@@ -1517,9 +1521,32 @@ void qsched_free ( struct qsched *s ) {
/* Destroy the mutex and condition. */
#ifdef HAVE_PTHREAD
if
(
s
->
flags
&
qsched_flag_pthread
)
{
/* Start all the threads on an empty function, to kill them. */
s
->
fun
=
NULL
;
s
->
barrier_count
=
s
->
runners_count
;
s
->
barrier_launchcount
=
s
->
runners_count
;
if
(
pthread_mutex_unlock
(
&
s
->
barrier_mutex
)
!=
0
||
pthread_cond_broadcast
(
&
s
->
barrier_cond
)
!=
0
)
error
(
"Failed to open the barrier."
);
/* Wait for each thread to have terminated. */
for
(
k
=
0
;
k
<
s
->
runners_count
;
k
++
)
if
(
pthread_join
(
s
->
runners
[
k
].
thread
,
NULL
)
!=
0
)
error
(
"Failed to join on thread %i."
,
k
);
/* Clean up the mutexes and barriers. */
if
(
pthread_cond_destroy
(
&
s
->
cond
)
!=
0
||
pthread_mutex_destroy
(
&
s
->
mutex
)
!=
0
)
error
(
"Error destroying pthread cond/mutex pair."
);
if
(
pthread_mutex_destroy
(
&
s
->
barrier_mutex
)
!=
0
||
pthread_cond_destroy
(
&
s
->
barrier_cond
)
!=
0
)
error
(
"Error destroying pthread barrier cond/mutex pair."
);
free
(
s
->
runners
);
s
->
runners_size
=
0
;
s
->
runners_count
=
0
;
}
#endif
/* Clear the flags. */
...
...
@@ -1591,6 +1618,7 @@ void qsched_init ( struct qsched *s , int nr_queues , int flags ) {
/* Init the pthread stuff. */
#ifdef HAVE_PTHREAD
if
(
flags
&
qsched_flag_pthread
)
{
if
(
pthread_cond_init
(
&
s
->
cond
,
NULL
)
!=
0
||
pthread_mutex_init
(
&
s
->
mutex
,
NULL
)
!=
0
)
error
(
"Error initializing yield cond/mutex pair."
);
...
...
@@ -1606,6 +1634,7 @@ void qsched_init ( struct qsched *s , int nr_queues , int flags ) {
s
->
barrier_launchcount
=
0
;
if
(
pthread_mutex_lock
(
&
s
->
barrier_mutex
)
!=
0
)
error
(
"Failed to lock barrier mutex."
);
}
#endif
/* Clear the timers. */
...
...
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