From 329732eef0264d044cc8ce0095e8ec56589dd400 Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Fri, 12 Jun 2020 09:40:21 +0200 Subject: Added ppmlib.h --- 04_exercise/rwlock/rwlock.c | 2 ++ 1 file changed, 2 insertions(+) (limited to '04_exercise/rwlock/rwlock.c') 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); -- cgit v1.2.3-54-g00ecf