summaryrefslogtreecommitdiffstats
path: root/04_exercise/rwlock/rwlock.c
diff options
context:
space:
mode:
authorStefan Zabka <zabkaste@hu-berlin.de>2020-06-12 09:40:21 +0200
committerStefan Zabka <zabkaste@hu-berlin.de>2020-06-12 09:40:21 +0200
commit329732eef0264d044cc8ce0095e8ec56589dd400 (patch)
tree045a4942c936e982d03367e6efdf087240967c47 /04_exercise/rwlock/rwlock.c
parent781a3f28a0f465350bf617b1f2c9ff70c0fbde9b (diff)
downloadbetriebssysteme-329732eef0264d044cc8ce0095e8ec56589dd400.tar.gz
betriebssysteme-329732eef0264d044cc8ce0095e8ec56589dd400.zip
Added ppmlib.h
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);