source: tests/concurrent/clib_tls.c @ 65502d8

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 65502d8 was 090a7c5, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Disable preemption in clib_tls.
The tls init feature is not very robust, but it is much less with preemption

  • 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
[a5e7233]16thread_local int checkval = 0xBAADF00D;
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.