Questions tagged [boost-context]

Boost.Context is a foundational library that provides a sort of cooperative multitasking on a single thread. By providing an abstraction of the current execution state in the current thread, an `fcontext_t` instance represents a specific point in the application's execution path. This is useful for building higher-level abstractions, like coroutines, cooperative threads (userland threads) or an equivalent to C# keyword `yield` in C++.

Boost.Context is a foundational library that provides a sort of cooperative multitasking on a single thread. By providing an abstraction of the current execution state in the current thread, including the stack (with local variables) and stack pointer, all registers and CPU flags, and the instruction pointer, an fcontext_t instance represents a specific point in the application's execution path. This is useful for building higher-level abstractions, like coroutines, cooperative threads (userland threads) or an equivalent to the C# keyword yield in C++.

An fcontext_t provides the means to suspend the current execution path and to transfer execution control, thereby permitting another fcontext_t to run on the current thread. This stateful transfer mechanism enables an fcontext_t to suspend execution from within nested functions and, later, to resume from where it was suspended. While the execution path represented by an fcontext_t only runs on a single thread, it can be migrated to another thread at any given time.

A context switch between threads requires system calls (involving the OS kernel), which can cost more than a thousand CPU cycles on x86 CPUs. By contrast, transferring control among them requires only fewer than a hundred CPU cycles because it does not involve system calls as it is done within a single thread.

More information about the Boost.Context library can be found on the boost website.

19 questions
0
votes
0 answers

Using Boost.coroutine2 on ARM bare-metal

I'm working on some embedded project, and I'd like to use coroutine in ARM cortex-M. Unfortunately, Boost.coroutine2 (which uses Boost.context inside) does not officially support it. Is there any way that I can tweak Boost library to be able to use…
eivour
  • 1,678
  • 12
  • 20
0
votes
1 answer

Boost Context implementation

I'm reading the implementation of boost fcontext. The function prototype of make_fcontext is typedef void* fcontext_t; fcontext_t BOOST_CONTEXT_CALLDECL make_fcontext( void * sp, std::size_t size, void (* fn)( intptr_t) ); The first argument is…
Jayce
  • 591
  • 1
  • 5
  • 13
0
votes
1 answer

make_fcontext/jump_fcontext used with shared stack

Is there a way to use boost context make_fcontext/jump_fcontext with a shared stack to share coroutine memory by saving/restoring the stack ? It seems that make_fcontext and jump_fcontext write on the stack themselves and I get crashes when trying…
Juicebox
  • 442
  • 4
  • 11
0
votes
2 answers

Boost: Single Threaded IO Service

In my app I will receive various events that I would like to process asynchronously in a prioritised order. I could do this with a boost::asio::io_service, but my application is single threaded. I don't want to pay for locks and mallocs you might…
RichardBruce
  • 641
  • 2
  • 10
  • 19
1
2