Skip to content

Commit

Permalink
make sure pthread gets freed on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
halayli committed Jan 28, 2012
1 parent e6cb598 commit dc41aa2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/lthread_compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ _lthread_compute_sched_create(void)
{
compute_sched_t *compute_sched = NULL;
pthread_t pthread;
pthread_attr_t attr;

if ((compute_sched = calloc(1, sizeof(compute_sched_t))) == NULL)
return NULL;
Expand All @@ -162,9 +161,8 @@ _lthread_compute_sched_create(void)
return NULL;
}

pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (pthread_create(&pthread,
&attr, _lthread_compute_run, compute_sched) != 0) {
NULL, _lthread_compute_run, compute_sched) != 0) {
_lthread_compute_sched_free(compute_sched);
return NULL;
}
Expand Down Expand Up @@ -237,6 +235,7 @@ _lthread_compute_run(void *arg)
struct timespec timeout;
int status = 0;

pthread_detach(pthread_self());
pthread_once(&key_once, once_routine);

pthread_setspecific(compute_sched_key, arg);
Expand Down

0 comments on commit dc41aa2

Please sign in to comment.