Synchronizing on a group of flags

An event flag group is an efficient and lightweight mechanism for synchronizing multiple threads, based on a 32bit value, in which each individual bit represents the state of a particular event defined by the application. Therefore, each group defines 32 individual events, from bit #0 to bit #31. Threads can wait for bits to be posted by other threads. Although EVL’s event flag group API is somewhat reminiscent of the eventfd interface, it is much simpler:

  • on the send side, posting the bits event mask to an event group is equivalent to performing atomically a bitwise OR operation such as group |= bits.

  • on the receive side, waiting for events means blocking until group becomes non-zero, at which point this value is returned to the thread heading the wait queue and the group is reset to zero in the same move. In other words, all bits set are immediately consumed by the first waiter and cleared in the group atomically. Threads wait on a group by priority order, which is determined by the scheduling policy they undergo.

Alt text

Unlike with the eventfd, there is no semaphore semantics associated to an event flag group, you may want to consider the EVL semaphore feature instead if this is what you are looking for.

Event flag group services