ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 6528d75 was
a5e7233,
checked in by Thierry Delisle <tdelisle@…>, 4 years ago
|
C interface now runs worker init routine in dedicated thread.
Also added test for this case.
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <clib/cfathread.h> |
---|
4 | #include <bits/defs.hfa> |
---|
5 | |
---|
6 | extern "C" { |
---|
7 | void _exit(int status); |
---|
8 | } |
---|
9 | |
---|
10 | thread_local int checkval = 0xBAADF00D; |
---|
11 | |
---|
12 | void init(void * ) { |
---|
13 | printf("Local Init\n"); |
---|
14 | checkval = 0xFEEDFACE; |
---|
15 | } |
---|
16 | |
---|
17 | void * checker( void * ) { |
---|
18 | for(int i = 0; i < 50; i++) { |
---|
19 | if(checkval != 0xFeedFace) { |
---|
20 | printf("Bad Food!\n"); |
---|
21 | } |
---|
22 | cfathread_yield(); |
---|
23 | } |
---|
24 | printf("Done\n"); |
---|
25 | return NULL; |
---|
26 | } |
---|
27 | |
---|
28 | int main() { |
---|
29 | init(NULL); |
---|
30 | cfathread_cluster_t cl = cfathread_cluster_self(); |
---|
31 | |
---|
32 | cfathread_cluster_add_worker( cl, NULL, init, NULL ); |
---|
33 | cfathread_cluster_add_worker( cl, NULL, init, NULL ); |
---|
34 | cfathread_cluster_add_worker( cl, NULL, init, NULL ); |
---|
35 | |
---|
36 | cfathread_attr_t attr; |
---|
37 | cfathread_attr_init(&attr); |
---|
38 | cfathread_attr_setcluster(&attr, cl); |
---|
39 | { |
---|
40 | printf("Starting Checkers\n"); |
---|
41 | cfathread_t t[7]; |
---|
42 | for(int i = 0; i < 7; i++) { |
---|
43 | cfathread_create( &t[i], &attr, checker, NULL ); |
---|
44 | } |
---|
45 | for(int i = 0; i < 7; i++) { |
---|
46 | cfathread_join( t[i], NULL ); |
---|
47 | } |
---|
48 | } |
---|
49 | cfathread_attr_destroy(&attr); |
---|
50 | fflush(stdout); |
---|
51 | _exit(0); |
---|
52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.