diff --git a/threads-cv/Makefile b/threads-cv/Makefile index 6b5378b..6f9af8b 100644 --- a/threads-cv/Makefile +++ b/threads-cv/Makefile @@ -4,6 +4,7 @@ CFLAGS := -Wall -Werror -I../include SRCS := join.c \ join_spin.c \ join_no_lock.c \ + join_no_state_var.c \ join_modular.c OBJS := ${SRCS:c=o} diff --git a/threads-cv/join_no_state_var.c b/threads-cv/join_no_state_var.c new file mode 100644 index 0000000..1badb43 --- /dev/null +++ b/threads-cv/join_no_state_var.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include "common.h" +#include "common_threads.h" + +pthread_cond_t c = PTHREAD_COND_INITIALIZER; +pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; + +void *child(void *arg) { + printf("child: begin\n"); + Mutex_lock(&m); + printf("child: signal\n"); + Cond_signal(&c); + Mutex_unlock(&m); + return NULL; +} +int main(int argc, char *argv[]) { + pthread_t p; + printf("parent: begin\n"); + Pthread_create(&p, NULL, child, NULL); + sleep(2); + printf("parent: wait to be signalled...\n"); + Mutex_lock(&m); + Cond_wait(&c, &m); + Mutex_unlock(&m); + printf("parent: end\n"); + return 0; +} +