Skip to content

Commit

Permalink
Merge pull request #1884 from chenBright/fix_double_delete_keytable
Browse files Browse the repository at this point in the history
fix the first bthread keytable on worker pthread will be deleted twice
  • Loading branch information
jamesge authored Aug 15, 2022
2 parents d82f866 + e1f7c9b commit a0fc1a2
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 a0fc1a2

Please sign in to comment.