C++ condition variable

Norman Feske norman.feske at ...1...
Fri May 26 09:36:36 CEST 2017

Hi Johannes,

> does Genode provide something similar to the standard C++ condition
> variable? I want to block a function call until a certain event occurs
> but I don't want to sleep and check for that event.

I wonder, may it be an option to avoid the reliance on blocking calls
and instead model your component as a state machine? I am asking because
we actually started out with the approach to block control flows just as
you wish for, but we moved (almost) completely away from it. Nowadays,
all modern Genode components are designed to handle I/O in an
asynchronous fashion. That is, the 'Component::construct' function
merely creates a "Main" object (that hosts signal handlers for
responding to external events) and returns immediately. Once it
returned, the component is able to respond to external events (e.g.,
I/O) via the signal handlers. When triggered, a signal handler applies a
state change to the component and returns. It never blocks.

All modern components follow this pattern to great success. So I
recommend you to design your component following the same approach. For
an illustrative nontrivial example, please have a look at

That said, for compatibility with ported 3rd-party software, we actually
provide an implementation of the pthread API including the support for
condition variables. You may have a look at 'libports/src/lib/pthread/'.
When using the libc, functions like 'read' and 'select' obviously block
for I/O. So technically, Genode covers that. But please be aware that
the use of POSIX goes against the grain of the actual Genode API. For
hosting existing 3rd-party software on Genode, there is no way around
it. But we shun it when creating new components from scratch.

I cannot give any statement about C++ condition variables specifically.
If they use the pthread API under the hood, you may be lucky to add
'stdcxx' to the 'LIBS' of your target. But as I said above, I'd advice
against it.


Dr.-Ing. Norman Feske
Genode Labs

http://www.genode-labs.com · http://genode.org

Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth

More information about the users mailing list