Created
September 4, 2018 12:00
-
-
Save dmytro-anokhin/8d35918d671735e5c7b44ec206088cbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Initialization of lock, pthread_rwlock_t is a value type and must be declared as var in order to refer it later. Make sure not to copy it. | |
| var lock = pthread_rwlock_t() | |
| pthread_rwlock_init(&lock, nil) | |
| // Protecting read section: | |
| pthread_rwlock_rdlock(&lock) | |
| // Read shared resource | |
| pthread_rwlock_unlock(&lock) | |
| // Protecting write section: | |
| pthread_rwlock_wrlock(&lock) | |
| // Write shared resource | |
| pthread_rwlock_unlock(&lock) | |
| // Clean up | |
| pthread_rwlock_destroy(&lock) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment