Fix thread-local PooledStackAllocator init order #1019
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
use_pooled_stack_allocator可能在程序很早的地方被调用,然而,PooledStackAllocator是一个thread-local变量,由于是按需使用alloc/dealloc,所以这个变量的初始化也很晚。在程序结束的时候,
PooledStackAllocator会优先于其他thread-local模块析构,于是造成了这些thread-local模块(已经使用了它分配的内存)产生coredump。这个MR在
use_pooled_stack_allocator的时候就初始化thread-local变量,并且把set_thread_stack_allocator放到thread.h模块,简化一些stack-allocator.h的代码use_pooled_stack_allocator may be called very early in the program. However, PooledStackAllocator is a thread-local variable, and due to the on-demand use of alloc/dealloc, the initialization of this variable is also very late.
At the end of the program, PooledStackAllocator will be destructed before other thread-local modules, which causes some thread-local modules (that have used the memory allocated by it) to generate coredumps.
This MR initializes the thread-local variable when use_pooled_stack_allocator is called, and moves
set_thread_stack_allocatorto thethread.hmodule to simplify some code instack-allocator.h.