c11threads
diff test.c @ 0:056c9db89e79
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 24 Sep 2012 12:32:42 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test.c Mon Sep 24 12:32:42 2012 +0300 1.3 @@ -0,0 +1,34 @@ 1.4 +#include <stdio.h> 1.5 +#include "c11threads.h" 1.6 + 1.7 +void tfunc(void *arg); 1.8 + 1.9 +int main(void) 1.10 +{ 1.11 + int i; 1.12 + thrd_t threads[4]; 1.13 + 1.14 + for(i=0; i<4; i++) { 1.15 + thrd_create(threads + i, tfunc, (void*)(long)i); 1.16 + } 1.17 + 1.18 + for(i=0; i<4; i++) { 1.19 + thrd_join(threads[i], 0); 1.20 + } 1.21 + 1.22 + return 0; 1.23 +} 1.24 + 1.25 +void tfunc(void *arg) 1.26 +{ 1.27 + int num = (long)arg; 1.28 + xtime dur; 1.29 + 1.30 + printf("hello from thread %d\n", num); 1.31 + 1.32 + dur.sec = 4; 1.33 + dur.nsec = 0; 1.34 + thrd_sleep(&dur); 1.35 + 1.36 + printf("thread %d done\n", num); 1.37 +}