Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

在bthread_key_create方法入参的析构函数destructor内部使用bthread-mutex存在的问题 #2554

Closed
MJY-HUST opened this issue Mar 1, 2024 · 0 comments · Fixed by #2558

Comments

@MJY-HUST
Copy link
Contributor

MJY-HUST commented Mar 1, 2024

问题产生场景:
当一个bthread(taskmeta中的attr.keytable_pool = null)的生命周期结束,且其拥有keytable实例时。在销毁keytable时会调用由用户创建bthread_key_create(bthread_key_t* key, void (destructor)(void data))中传入的destructor析构函数,如果destructor内部使用了bthread-mutex并挂起的话,bthread恢复后所在的task_group会发生变化。在现有的task_runner实现中,如果在return_keytable后不重新指定task_group的话,调用ending_sched(&g)会出现错误。

疑问:

  1. destructor内部不能使用bthread-mutex吗?我没有在相关的文档或者代码中找到相关的说明。在destructor内部使用bthread-mutex的一种场景是(通过一个链表将所有的bthread-local变量串起来,便于统一操作,例如置为过期。在析构bthread-local时,需要加锁从链表中摘除该元素)。
  2. 如果支持使用的话,需要将
    g = BAIDU_GET_VOLATILE_THREAD_LOCAL(tls_task_group);移动到调用return_keytable后:也就是从task_group.cc line311 移动到line334。
    1709291988287
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant