Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
useCondVar.H File Reference

Wrapper class for POSIX condition variables. More...

#include <pthread.h>
Include dependency graph for useCondVar.H:

Go to the source code of this file.

Classes

class  UseCondVar
 Wrapper class for POSIX condition variables. More...
 

Detailed Description

Wrapper class for POSIX condition variables.

This file provides a simple C++ wrapper around pthread condition variables, offering a cleaner interface for thread synchronization.

Features

  • Wait: Block until signaled
  • Signal: Wake one waiting thread
  • Broadcast: Wake all waiting threads

Usage Example

pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_mutex_init(&mutex, nullptr);
pthread_cond_init(&cond, nullptr);
// In waiting thread:
{
UseMutex lock(&mutex);
UseCondVar cv(&cond, &mutex);
while (!condition_met)
cv.wait();
}
// In signaling thread:
{
UseMutex lock(&mutex);
condition_met = true;
UseCondVar cv(&cond, &mutex);
cv.signal();
}
Wrapper class for POSIX condition variables.
Definition useCondVar.H:102
RAII-style mutex lock guard.
Definition useMutex.H:142
Note
Always hold the associated mutex when calling wait/signal/broadcast.
Consider using std::condition_variable for modern C++ code.
See also
useMutex.H For the companion mutex wrapper
Author
Leandro Rabindranath León *

Definition in file useCondVar.H.