source: tests/concurrent/multi-monitor.cfa @ b9696a8

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since b9696a8 was 107b01a, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Several changes to the makefiles

  • change .c tests to .cfa
  • add require for libtool in configure
  • libtoolize to fix some warnings
  • Property mode set to 100644
File size: 986 bytes
RevLine 
[73abe95]1#include <fstream.hfa>
2#include <kernel.hfa>
3#include <monitor.hfa>
4#include <thread.hfa>
[2781e65]5
6static int global12, global23, global13;
7
[bcda04c]8monitor monitor_t {};
[ef42b143]9
10static monitor_t m1, m2, m3;
[2781e65]11
[83a071f9]12void increment( monitor_t & mutex p1, monitor_t & mutex p2, int & value ) {
13        value += 1;
[2781e65]14}
15
[83a071f9]16thread MyThread {
[2781e65]17        int target;
18};
19
[00e80b6]20void ?{}( MyThread & this, int target ) {
21        this.target = target;
[2781e65]22}
23
[00e80b6]24void ^?{}( MyThread & mutex this ) {}
[cb0e6de]25
[83a071f9]26void main( MyThread & this ) {
[2781e65]27        for(int i = 0; i < 1000000; i++) {
[83a071f9]28                choose(this.target) {
29                        case 0: increment( m1, m2, global12 );
30                        case 1: increment( m2, m3, global23 );
31                        case 2: increment( m1, m3, global13 );
[2781e65]32                }
33        }
34}
35
[83a071f9]36forall(dtype T | sized(T) | { void ^?{}(T & mutex); })
37void delete_mutex(T * x) {
38        ^(*x){};
39        free(x);
40}
41
[2781e65]42int main(int argc, char* argv[]) {
43        processor p;
44        {
[83a071f9]45                MyThread * f[6];
[2781e65]46                for(int i = 0; i < 6; i++) {
[83a071f9]47                        f[i] = new(i % 3);
[2781e65]48                }
49
50                for(int i = 0; i < 6; i++) {
[83a071f9]51                        delete_mutex( f[i] );
[2781e65]52                }
53        }
[200fcb3]54        sout | global12 | global23 | global13;
[00e80b6]55}
Note: See TracBrowser for help on using the repository browser.