|
Boost : |
Subject: Re: [boost] [boost::context] reusing stacks
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2012-11-27 02:25:10
Am 27.11.2012 00:45 schrieb "Valentin Milea" <valentin.milea_at_[hidden]>:
>
> Hi,
>
> I'm working on a tiny coroutine library based on boost::context. For
> performance reasons I'd rather keep a pool of stacks instead
> allocating/deallocating every time. Is it legal to reuse a stack for a
> different context?
yes, but only one context is allowed to own the stack. If the context is
deallocated you could asign the stack to another context via
make_fcontext() instead to deallocate it.
Therefore your code is not correct (two context's share the same stack at
the same time).
> int main(int argc, char * argv[])
> {
> ctx::guarded_stack_allocator alloc;
>
> std::size_t size =
ctx::guarded_stack_allocator::default_stacksize();
> void *sp = alloc.allocate(size);
>
> fc = ctx::make_fcontext(sp, size, f1);
> std::cout << "main: jump 1" << std::endl;
> ctx::jump_fcontext(&fcm, fc, 0);
>
> fc = ctx::make_fcontext(sp, size, f2); // legal? No
> std::cout << "main: jump 2" << std::endl;
> ctx::jump_fcontext(&fcm, fc, 0);
>
> std::cout << "main: done" << std::endl;
>
> return 0;
> }
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk