ADTast-experimentalpthread-emulation
Last change
on this file since f403c46 was
1bcbf02,
checked in by Thierry Delisle <tdelisle@…>, 2 years ago
|
Changed declarations using _Thread_local to use thread.
I'm fairly sure they do exactly the same, but thread is:
- more consistent with uC++.
- Shorter.
- Better documented.
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <clib/cfathread.h> |
---|
4 | #include <bits/defs.hfa> |
---|
5 | #include <time_t.hfa> |
---|
6 | |
---|
7 | extern "C" { |
---|
8 | void _exit(int status); |
---|
9 | } |
---|
10 | |
---|
11 | Duration default_preemption(){ |
---|
12 | return 0; |
---|
13 | } |
---|
14 | |
---|
15 | |
---|
16 | __thread int checkval = 0xBAADF00D; |
---|
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.