source: tests/concurrency/migrate.cfa @ 50e04cc

Last change on this file since 50e04cc was c26bea2a, checked in by Peter A. Buhr <pabuhr@…>, 19 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.7 KB
Line 
1#include <fstream.hfa>
2#include <kernel.hfa>
3#include <thread.hfa>
4
5#include <stdatomic.h>
6#include <assert.h>
7
8struct cluster_wrapper {
9        cluster self;
10        const uint64_t canary;
11        struct {
12                volatile uint64_t want;
13                volatile uint64_t have;
14        } checksum;
15};
16
17void ?{}( cluster_wrapper & this ) {
18        (this.self){};
19        (*(uint64_t *)&this.canary) = 0xDEAD2BADDEAD2BAD;
20        this.checksum.want = 0;
21        this.checksum.have = 0;
22}
23
24void ^?{}( cluster_wrapper & this ) {
25        assert(this.canary == 0xDEAD2BADDEAD2BAD);
26}
27
28static cluster_wrapper * the_clusters;
29static unsigned cluster_cnt;
30
31thread MyThread {
32
33};
34
35void ?{}( MyThread & this ) {}
36
37void checkcl( MyThread & this, cluster * cl) {
38        if(((thread&)this).curr_cluster != cl) {
39                abort | "Thread has unexpected cluster";
40        }
41}
42
43void main( MyThread & this ) {
44        waitfor( migrate : this ) {
45                assert( ((thread&)this).curr_cluster == active_cluster() );
46                assert( ((thread&)this).curr_cluster == active_processor()->cltr );
47        }
48
49        struct cluster_wrapper * curr = (struct cluster_wrapper *)&the_clusters[0];
50
51        for(100) {
52                unsigned idx = prng( this, cluster_cnt );
53
54                struct cluster_wrapper * next = &the_clusters[ idx ];
55                assert(next->canary == 0xDEAD2BADDEAD2BAD);
56
57                // next->
58
59                migrate( this, next->self );
60
61                assert( active_cluster() == &next->self );
62                assert( ((thread&)this).curr_cluster == active_cluster() );
63                assert( ((thread&)this).curr_cluster == active_processor()->cltr );
64        }
65}
66
67int main() {
68        cluster_cnt = 3;
69        cluster_wrapper cl[cluster_cnt];
70        the_clusters = cl;
71
72        {
73                set_concurrency( cl[0].self, 2 );
74                set_concurrency( cl[1].self, 2 );
75                set_concurrency( cl[2].self, 1 );
76
77                MyThread threads[17];
78                for(i;17) {
79                        migrate( threads[i], cl[0].self );
80                }
81
82        }
83        // non-empty .expect file
84        printf( "done\n" );
85}
Note: See TracBrowser for help on using the repository browser.