Skip to content

Instantly share code, notes, and snippets.

@dmytro-anokhin
Created September 4, 2018 12:00
Show Gist options
  • Select an option

  • Save dmytro-anokhin/8d35918d671735e5c7b44ec206088cbc to your computer and use it in GitHub Desktop.

Select an option

Save dmytro-anokhin/8d35918d671735e5c7b44ec206088cbc to your computer and use it in GitHub Desktop.
// 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