c++boostboost-context

Boost 1.57 Boost.Context fcontext_t resource management


Some context

In Boost 1.57 f_context & make_fcontext looks like this

// fcontext.hpp:
typedef void* fcontext_t;
fcontext_t BOOST_CONTEXT_CALLDECL make_fcontext( void * sp, std::size_t size, void (* fn)( intptr_t) );

How should I manage the resource returned by make_fcontext()?

I have read the docs, asked on IRC and looked at the examples, but could not find anything. Is there a need to release/delete/close this resource?


Solution

  • For users, fcontext_t is a handle to identify context, and specify which context to jump to with jump_fcontext(). The object pointed to by the opaque pointer returned from make_fcontext(stack, context_function) will be managed by the provided stack. The documentation states:

    Creates an fcontext_t on top of the stack [...]

    One can also look into the Boost.Coroutine's implementation to see its usage of fcontext_t.