-
Notifications
You must be signed in to change notification settings - Fork 3
Threads
This library implements a complete cooperative multi-threading system. The interface is identical to the standard Thread Support library introduced in C++11, with some additional extensions. These are listed on this page.
The primary difference is that the scheduling system is cooperative, which means
you must regularly call yield()
to allow other threads to execute. A good
opportunity to do so is while waiting for external events.
Fully implemented in <jw/thread.h>
An additional constructor is provided to specify the stack size.
Attempts to stop the thread by throwing a detail::abort_thread
exception. If
this exception is inadvertently caught, terminate()
is called.
Returns true
while the thread is live (not aborted or exited).
Invokes the given function in this thread's context.
Allows you to set a name for the thread, which will be displayed in gdb. This
function is a no-op when compiled with NDEBUG
.
The extensions for thread
also apply to jthread
.
Contains the following functions to switch to other threads:
yield
yield_while
yield_until
yield_for
yield_while_until
yield_while_for
Additionally, alias functions sleep_...()
are provided. These simply call
the equivalent yield_...()
. Use whichever you prefer.
Note that the interrupt flag is 'thread-local', that is, calling any yield function will re-enable interrupts if they were previously disabled.
Registers the given function to be called on the next active thread.
As above, but for the main thread.
Implemented in <jw/mutex.h>
. Locking functionality (unique_lock
, etc) is
provided by libstc++.
The mutex classes in this header are based on atomic primitives, so they are suitable for use in interrupt context. The recursive mutexes also consider (potentially nested) interrupt contexts to be separate 'threads'.
Not implemented.
Fully implemented in <jw/shared_mutex.h>
.
A complete implementation is provided by libstdc++, with no dependency on pthreads.
Fully implemented in <jw/future.h>
. Some basic functionality (future_error
,
launch
, etc) is provided by libstc++.
Policy std::launch::deferred
is not implemented.
Not (yet) implemented.
Not (yet) implemented.
Not (yet) implemented.
Not (yet) implemented.