Skip to content

Commit

Permalink
fizzbuzz68.c: sched_yield()
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-S-Thompson committed Dec 8, 2015
1 parent 1d58dec commit 2b3bb87
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions fizzbuzz68.c
@@ -1,9 +1,9 @@
#define _POSIX_C_SOURCE 199309L

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sched.h>

static int lines_printed = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
Expand Down Expand Up @@ -31,8 +31,7 @@ static void *thread_routine(void *arg) {
else {
try(pthread_mutex_unlock(&mutex));
}
enum { MILLISECOND = 1000000 };
nanosleep(&(struct timespec){.tv_sec = 0, .tv_nsec = MILLISECOND}, NULL);
sched_yield();
}
}

Expand Down

0 comments on commit 2b3bb87

Please sign in to comment.