source: tests/concurrent/clib_tls.c @ 8463136

ast-experimental
Last change on this file since 8463136 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
RevLine 
[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
7extern "C" {
8void _exit(int status);
9}
10
[090a7c5]11Duration default_preemption(){
12        return 0;
13}
14
15
[1bcbf02]16__thread int checkval = 0xBAADF00D;
[a5e7233]17
18void init(void * ) {
19        printf("Local Init\n");
20        checkval = 0xFEEDFACE;
21}
22
23void * 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
34int 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.