In my work on group commit for MariaDB, I have the following situation:
A group of threads are going to participate in group commit. This
means that one of the threads, called the group leader,
will run an fsync()
for all of them, while the other
threads wait. Once the group leader is done, it needs to wake up
all of the other threads.
The obvious way to do this is to have the group leader call
pthread_cond_broadcast()
on a condition that the
other threads are waiting for with pthread_cond_wait():
bool wakeup= false; pthread_cond_t wakeup_cond; pthread_mutex_t wakeup_mutex
Waiter:
pthread_mutex_lock(&wakeup_mutex); while (!wakeup) pthread_cond_wait(&wakeup_cond, &wakeup_mutex); pthread_mutex_unlock(&wakeup_mutex); // Continue processing after group commit …[Read more]