Variable conditions allow you to wait for a specific event and have a different signal stream that has a condition variable.
You may have a thread that does this:
for (;;) { if (avail() > 0) do_work(); else pthread_cond_wait(); }
and another thread that does this:
for (;;) { put_work(); pthread_cond_signal(); }
Very simplified, of course. :) You will need to see how to use it correctly, there are some difficulties with working with state variables due to race conditions.
However, if you are sure that the flow will block for a very short time (in the order of ΞΌs) and rarely, using such a spin cycle is likely to be more efficient.
source share