From a5638de011870dbdce899aebb84cd1042f672ae6 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 20 Apr 2014 09:58:47 +0200 Subject: [PATCH] add my own broken example for uiowa-threads.c --- .gitignore | 1 + Makefile | 6 +++++- uiowa-threads-my-example.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 uiowa-threads-my-example.c diff --git a/.gitignore b/.gitignore index 6536776..c2ab9bb 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ multibrot-openmp.png hello-openmp mandelbrot-openmp positional-format-strings +uiowa-threads-my-example diff --git a/Makefile b/Makefile index b4cb6e3..1ef5278 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ CFLAGS_OPENMP=$(CFLAGS) -fopenmp TARGETS=approximate-pi linked-list mandelbrot threads circular-buffer structs \ ncurses-pong bit-fuckery bit-fuckery2 checkcheck multibrot bloom \ - wo-lernen lua-foo binsearch test-inline-assembly uiowa-threads-example \ + wo-lernen lua-foo binsearch test-inline-assembly \ + uiowa-threads-example uiowa-threads-my-example \ mtrace-test av-variance undefined-behaviour \ multibrot-openmp hello-openmp mandelbrot-openmp \ positional-format-strings @@ -81,6 +82,9 @@ mtrace-test.txt: mtrace-test.trace uiowa-threads-example: uiowa-threads.o uiowa-threads-example.c $(CC) $(CFLAGS) -o $@ $^ +uiowa-threads-my-example: uiowa-threads.o uiowa-threads-my-example.c + $(CC) $(CFLAGS) -o $@ $^ + av-variance: av-variance.c $(CC) $(CFLAGS) -o $@ $< -lm diff --git a/uiowa-threads-my-example.c b/uiowa-threads-my-example.c new file mode 100644 index 0000000..1087cee --- /dev/null +++ b/uiowa-threads-my-example.c @@ -0,0 +1,28 @@ +#include +#include "uiowa-threads.h" + +void test_thread(int n) { + for (int i=0; i<10; i++) { + printf("thread %d: %d\n", n, i); + thread_relinquish(); + } +} + +void test_thread2(int n) { + for (int i=0; i<10; i++) { + printf("thread %d: %d\n", n, i); + thread_relinquish(); + } +} + +int main() +{ + thread_manager_init(); + thread_startup_report(); + + thread_launch(4000, test_thread, 1); + thread_launch(4000, test_thread2, 2); + + thread_manager_start(); + /* control never reaches this point */ +}