ast-experimental
Last change
on this file since ded6c2a6 was
c26bea2a,
checked in by Peter A. Buhr <pabuhr@…>, 18 months ago
|
first attempt at renaming directory tests/concurrent to tests/concurrency to harmonize with other concurrency directory names
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[a5e7233] | 1 | #include <stdio.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <clib/cfathread.h> |
---|
| 4 | #include <bits/defs.hfa> |
---|
[090a7c5] | 5 | #include <time_t.hfa> |
---|
[a5e7233] | 6 | |
---|
| 7 | extern "C" { |
---|
| 8 | void _exit(int status); |
---|
| 9 | } |
---|
| 10 | |
---|
[090a7c5] | 11 | Duration default_preemption(){ |
---|
| 12 | return 0; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | |
---|
[1bcbf02] | 16 | __thread int checkval = 0xBAADF00D; |
---|
[a5e7233] | 17 | |
---|
| 18 | void init(void * ) { |
---|
| 19 | printf("Local Init\n"); |
---|
| 20 | checkval = 0xFEEDFACE; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | void * checker( void * ) { |
---|
| 24 | for(int i = 0; i < 50; i++) { |
---|
| 25 | if(checkval != 0xFeedFace) { |
---|
| 26 | printf("Bad Food!\n"); |
---|
| 27 | } |
---|
| 28 | cfathread_yield(); |
---|
| 29 | } |
---|
| 30 | printf("Done\n"); |
---|
| 31 | return NULL; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | int main() { |
---|
| 35 | init(NULL); |
---|
| 36 | cfathread_cluster_t cl = cfathread_cluster_self(); |
---|
| 37 | |
---|
| 38 | cfathread_cluster_add_worker( cl, NULL, init, NULL ); |
---|
| 39 | cfathread_cluster_add_worker( cl, NULL, init, NULL ); |
---|
| 40 | cfathread_cluster_add_worker( cl, NULL, init, NULL ); |
---|
| 41 | |
---|
| 42 | cfathread_attr_t attr; |
---|
| 43 | cfathread_attr_init(&attr); |
---|
| 44 | cfathread_attr_setcluster(&attr, cl); |
---|
| 45 | { |
---|
| 46 | printf("Starting Checkers\n"); |
---|
| 47 | cfathread_t t[7]; |
---|
| 48 | for(int i = 0; i < 7; i++) { |
---|
| 49 | cfathread_create( &t[i], &attr, checker, NULL ); |
---|
| 50 | } |
---|
| 51 | for(int i = 0; i < 7; i++) { |
---|
| 52 | cfathread_join( t[i], NULL ); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | cfathread_attr_destroy(&attr); |
---|
| 56 | fflush(stdout); |
---|
| 57 | _exit(0); |
---|
| 58 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.