linux futexes: non-blocking integer valued condition variables

POSIX’ condition variables pthread_cond_t unfortunately have some drawbacks:

  • They require the use of at least two separate other objects that are only loosely coupled with the condition variable itself:

    • A plain variable, say X of type int, that actually holds the value of which the condition depends.
    • A mutex that is just to regulate the access to X and to the condition variable.
  • Generally they are not lock free. To access X we have to

    • lock the mutex
    • inspect X
    • eventually wait for the condition to become true
    • do changes
    • eventually signal other waiters about the changes we made
    • unlock the mutex

Linux’ concept of futexes allows to associate an equivalent concept directly to the variable X and to access this variable without taking locks directly in most of the cases.
Continue reading “linux futexes: non-blocking integer valued condition variables”


VLA as function arguments

Now that we aren’t afraid of variably modified types anymore let us have a look on how these can be used as function arguments.

Therefore we will

Continue reading “VLA as function arguments”

don’t be afraid of variably modified types

This post is about a subject that easily triggers a lot of polemic and diverging opinions, so I will try to be careful to get things right. In any case the message of this post may be summarized as:

  • Plain variable length arrays (VLA) might be dangerous for your health, since they may cause stack overflows, and generally are not so easy to handle
  • In constrast to that pointers to VLA are a quite different story and may ease the programming with multi-dimensional arrays substantially.

Continue reading “don’t be afraid of variably modified types”