[fiber] pooled_fixedsize_stack
Hi, I'm trying to replace fixedsize_stack with pooled_fixedsize_stack in my application witch spawns many fibers to reduce allocations, and got random crashes. For reproduction it is enough to replace fixedsize_stack with pooled_fixedsize_stack in performance\fiber\skynet_stealing_detach.cpp. Playing with stack size parameter does not help. Can anyone give some tip how to use pooled stack with fiber correctly? -- Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
I realized that pooled_fixed_stack is not thread safe. Now the question is how to make pooled_fixed_stack mutithread safe? -- Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
On 14/09/2017 03:03, DePizzottri via Boost-users wrote:
I realized that pooled_fixed_stack is not thread safe. Now the question is how to make pooled_fixed_stack mutithread safe?
Fibers are usually bound to a single thread each; can't you just use a separate stack instance for each thread?
Boost - Users mailing list wrote
On 14/09/2017 03:03, DePizzottri via Boost-users wrote:
I realized that pooled_fixed_stack is not thread safe. Now the question is how to make pooled_fixed_stack mutithread safe?
Fibers are usually bound to a single thread each; can't you just use a separate stack instance for each thread?
_______________________________________________ Boost-users mailing list
Boost-users@.boost
Yes, i tried to instantiate pfs as thread_local inside fiber routine that spawns other fibers: thread_local bf::pooled_fixedsize_stack salloc{ 2 * bf::pooled_fixedsize_stack::traits_type::page_size() }; crashes become rare, but did not completely disappear. I thought that allocate call to stack allocator appears only at fiber creation time inside parent's body, but it seems to be there is exists some other conditions that cause race. -- Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
2017-09-14 6:12 GMT+02:00 DePizzottri via Boost-users < boost-users@lists.boost.org>:
Boost - Users mailing list wrote
On 14/09/2017 03:03, DePizzottri via Boost-users wrote:
I realized that pooled_fixed_stack is not thread safe. Now the question is how to make pooled_fixed_stack mutithread safe?
Fibers are usually bound to a single thread each; can't you just use a separate stack instance for each thread?
_______________________________________________ Boost-users mailing list
Boost-users@.boost
Yes, i tried to instantiate pfs as thread_local inside fiber routine that spawns other fibers:
thread_local bf::pooled_fixedsize_stack salloc{ 2 * bf::pooled_fixedsize_stack::traits_type::page_size() };
crashes become rare, but did not completely disappear.
I thought that allocate call to stack allocator appears only at fiber creation time inside parent's body, but it seems to be there is exists some other conditions that cause race.
each fiber has its own stack (provided by the stack allocator) a fiber can only migrated between threads if it is in the suspended state the skynet_stealing_xyz.cpp does work-stealing (ready fibers are migrated between threads) - if you apply 'thread_local' to stack_allocator you will end up in a race if the fiber was migrated to another thread and tries to release its stack. the allocator has to be protected by a lock or you use a lockless algorithm BTW, the memory allocator used by your libc usually does already cache the memory (depends on the algorithm and chunk size)
each fiber has its own stack (provided by the stack allocator) a fiber can only migrated between threads if it is in the suspended state the skynet_stealing_xyz.cpp does work-stealing (ready fibers are migrated between threads) - if you apply 'thread_local' to stack_allocator you will end up in a race if the fiber was migrated to another thread and tries to release its stack.
I completely forgot that the memory will be released, thank you.
BTW, the memory allocator used by your libc usually does already cache the memory (depends on the algorithm and chunk size)
Yes, but I want to increase a speed by exploiting the benefits of boost::pool when allocating a large number of equal size objects (stacks). Hope it will be faster then simple tcmalloc. -- Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
participants (3)
-
DePizzottri
-
Gavin Lambert
-
Oliver Kowalke