zdz
zdz
FIX BUG(Issue #1776): Switching pthread causes coredump when bthread 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...
**Describe the bug (描述bug)** ### 问题1 使用了bthread local会以一定概率出现coredump,并且core的栈不固定,但大多在bthread::TaskGroup::sched_to的 errno = saved_errno;,分析后发现是由于注册的bthread local析构函数调用了bthread_mutex_lock会引发bthread local析构的时候出发bthread切换导致的,如下  1. 假设bthread1在pthread1上调用return_keytable最终会调用用户注册的bthread local析构函数,如果这个析构函数调用了bthread_mutex_lock等会导致bthread切换的函数则会使得执行return_keytable之后bthread1切换到另一个线程pthread2上 2. 由于g还是用的pthread1上的thread local tls_task_group,在pthread2调用g->set_remained(TaskGroup::_release_last_context, m);会使得pthread1提前将bthread1的stack释放掉,如果此时另一个bthread2申请到了这个stack则会导致bthread1和bthread2共用了同一个stack,会导致互相踩栈引发coredump ### 问题1修复  可以移动g = tls_task_group到bthread local析构函数之后的位置修复 ###...