Skip to content

Commit

Permalink
fix the problem that the first bthread keytable on worker pthread wil…
Browse files Browse the repository at this point in the history
…l be deleted twice
  • Loading branch information
chenguangming committed Aug 12, 2022
1 parent 6495704 commit e1f7c9b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/bthread/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,14 @@ int bthread_setspecific(bthread_key_t key, void* data) {
bthread::TaskGroup* const g = bthread::tls_task_group;
if (g) {
g->current_task()->local_storage.keytable = kt;
}
if (!bthread::tls_ever_created_keytable) {
bthread::tls_ever_created_keytable = true;
CHECK_EQ(0, butil::thread_atexit(bthread::cleanup_pthread, kt));
} else {
// Only cleanup keytable created by pthread.
// keytable created by bthread will be deleted
// in `return_keytable' or `bthread_keytable_pool_destroy'.
if (!bthread::tls_ever_created_keytable) {
bthread::tls_ever_created_keytable = true;
CHECK_EQ(0, butil::thread_atexit(bthread::cleanup_pthread, kt));
}
}
}
return kt->set_data(key, data);
Expand Down

0 comments on commit e1f7c9b

Please sign in to comment.