summaryrefslogtreecommitdiffstats
path: root/04_exercise/rwlock/rwlock.c
diff options
context:
space:
mode:
Diffstat (limited to '04_exercise/rwlock/rwlock.c')
-rw-r--r--04_exercise/rwlock/rwlock.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/04_exercise/rwlock/rwlock.c b/04_exercise/rwlock/rwlock.c
index 3de5083..941d176 100644
--- a/04_exercise/rwlock/rwlock.c
+++ b/04_exercise/rwlock/rwlock.c
@@ -34,6 +34,7 @@ void rwUnlockWrite(atomic_char *lock) {
if(DEBUG) {
fprintf(stderr, "Thread %lu: Released Write Lock \n", pthread_self() % 1000);
}
+ // Avoid starvation of readers/all other threads
if (sched_yield() < 0) {
perror("Couldn't sleep. This shouldn't happen.");
exit(-1);
@@ -60,6 +61,7 @@ void rwUnlockRead(atomic_char *lock) {
if(DEBUG) {
fprintf(stderr, "Thread %lu: Released Read Lock \n", pthread_self() % 1000);
}
+ // Avoid starvation of writer/all other threads
if (sched_yield() < 0) {
perror("Couldn't sleep. This shouldn't happen.");
exit(-1);