Skip to content

Commit

Permalink
FIX BUG(Issue #1776): Switching pthread causes coredump when bthread …
Browse files Browse the repository at this point in the history
…local variable is destructed

If the bthread local destructor specified by bthread_key_create calls bthread_mutex_lock
it may cause TaskGroup::task_runner->return_keytable to switch pthreads after execution
causing coredump
  • Loading branch information
dongzhizhao committed Jun 6, 2022
1 parent c1dc6e8 commit f6e7627
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/bthread/task_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@ void TaskGroup::task_runner(intptr_t skip_remained) {
thread_return = e.value();
}

// Group is probably changed
g = tls_task_group;

// TODO: Save thread_return
(void)thread_return;

Expand All @@ -314,13 +311,16 @@ void TaskGroup::task_runner(intptr_t skip_remained) {
// Clean tls variables, must be done before changing version_butex
// otherwise another thread just joined this thread may not see side
// effects of destructing tls variables.
KeyTable* kt = tls_bls.keytable;
KeyTable* kt = m->local_storage.keytable;
if (kt != NULL) {
return_keytable(m->attr.keytable_pool, kt);
// After deletion: tls may be set during deletion.
tls_bls.keytable = NULL;
m->local_storage.keytable = NULL; // optional
}

// Group is probably changed
g = tls_task_group;

// Increase the version and wake up all joiners, if resulting version
// is 0, change it to 1 to make bthread_t never be 0. Any access
Expand Down

0 comments on commit f6e7627

Please sign in to comment.