Articles contenant le tag read-write lock

Bad idea: get a read lock while holding a write lock

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 »); […]

, , , ,

4 commentaires