, , , , .
, thread1 (. thread1 -), , thread2 thread3 . pthread_cond_wait , .
You can use a mutex read-write type pthread_rwlock_t. Essentially, it thread1does write lock, so other threads will be blocked when trying to get a read lock.
The functions for this lock are self-explanatory:
int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,
const pthread_rwlockattr_t *restrict attr);
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
When thread1completed its initialization, it unlocks. Other threads will perform read locks, and since more read locks can coexist, they can execute simultaneously. Again: this is valid if you are not writing to thread2 & 3 on shared resources.
source
share