Articles contenant le tag pthread
C++ Thread synchronization pitfall: using a barrier to synchronize a thread start
Posté par Olivier dans Trucs & Astuces le 20 novembre 2013
The context: You want to create a worker thread. Before the main thread goes on, you want to ensure that the worker thread starts. Using a boost::barrier seems like a good idea.
Bad idea: get a read lock while holding a write lock
Posté par Olivier dans Trucs & Astuces le 4 novembre 2009
Under Linux, the following code hangs in the second execution of the loop at the time the write lock is acquired. pthread_rwlock_t lock; fprintf(stderr, « Init\n »); pthread_rwlock_init(&lock, NULL); for(int i = 0; i < 2; ++i) { fprintf(stderr, « Get Write lock\n »); pthread_rwlock_wrlock(&lock); fprintf(stderr, « Get Read lock\n »); pthread_rwlock_rdlock(&lock); fprintf(stderr, « Release Read lock\n »); pthread_rwlock_unlock(&lock); fprintf(stderr, « Release Write lock\n »); […]