spinning cv example too

This commit is contained in:
Remzi Arpaci-Dusseau
2019-04-29 14:42:03 -05:00
parent a2d7e3595d
commit 606f0e004f
2 changed files with 25 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ CC := gcc
CFLAGS := -Wall -Werror -I../include
SRCS := join.c \
join_spin.c \
join_modular.c
OBJS := ${SRCS:c=o}

24
threads-cv/join_spin.c Normal file
View File

@@ -0,0 +1,24 @@
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include "common.h"
#include "common_threads.h"
volatile int done = 0;
void *child(void *arg) {
printf("child\n");
sleep(5);
done = 1;
return NULL;
}
int main(int argc, char *argv[]) {
pthread_t p;
printf("parent: begin\n");
Pthread_create(&p, NULL, child, NULL);
while (done == 0)
; // spin
printf("parent: end\n");
return 0;
}