From 606f0e004fc263c0e3d38d9a1cf06bea6f293be7 Mon Sep 17 00:00:00 2001 From: Remzi Arpaci-Dusseau Date: Mon, 29 Apr 2019 14:42:03 -0500 Subject: [PATCH] spinning cv example too --- threads-cv/Makefile | 1 + threads-cv/join_spin.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 threads-cv/join_spin.c diff --git a/threads-cv/Makefile b/threads-cv/Makefile index 0124b54..b83ce38 100644 --- a/threads-cv/Makefile +++ b/threads-cv/Makefile @@ -2,6 +2,7 @@ CC := gcc CFLAGS := -Wall -Werror -I../include SRCS := join.c \ + join_spin.c \ join_modular.c OBJS := ${SRCS:c=o} diff --git a/threads-cv/join_spin.c b/threads-cv/join_spin.c new file mode 100644 index 0000000..837b723 --- /dev/null +++ b/threads-cv/join_spin.c @@ -0,0 +1,24 @@ +#include +#include +#include +#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; +}