source: tests/concurrent/waitfor/dtor.cfa @ 0dbecad

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0dbecad was cca568e, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

change all example waitfor statements from comma separate to colon

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[b8116cd]1//---------------------------------------------------------
2// Barging test
3// Ensures the statement order is reverse when using waitfor ^?{}
4//---------------------------------------------------------
5
[73abe95]6#include <fstream.hfa>
7#include <kernel.hfa>
8#include <monitor.hfa>
9#include <stdlib.hfa>
10#include <thread.hfa>
[b8116cd]11
12#include <stdbool.h>
13
14static const unsigned long N = 5_000ul;
15
[ca278c1]16enum state_t {
17        CTOR,
18        MAIN,
19        AFTER,
20        END,
21        DTOR
22};
23
24thread dummy_t {
25        state_t state;
26};
27
28static inline void set_state( dummy_t & this, state_t state) {
29        switch(state) {
30                case CTOR  : break;
[200fcb3]31                case MAIN  : if( this.state != CTOR  ) { serr | "ERROR Expected state to be CTOR" ; abort(); } this.state = state; break;
32                case AFTER : if( this.state != MAIN  ) { serr | "ERROR Expected state to be MAIN" ; abort(); } this.state = state; break;
33                case END   : if( this.state != AFTER ) { serr | "ERROR Expected state to be AFTER"; abort(); } this.state = state; break;
34                case DTOR  : if( this.state != END   ) { serr | "ERROR Expected state to be END"  ; abort(); } this.state = state; break;
[ca278c1]35        }
36}
[b8116cd]37
38void ^?{}( dummy_t & mutex this ) {
[ca278c1]39        set_state( this, DTOR );
40}
41
42void ?{}( dummy_t & this ) {
43        this.state = CTOR;
[b8116cd]44}
45
46void main( dummy_t & this ) {
[6c7b1e7]47        yield(random( 10 ));
[ca278c1]48        set_state( this, MAIN );
[cca568e]49        waitfor( ^?{} : this ) {
[ca278c1]50                set_state( this, AFTER );
[b8116cd]51        }
[ca278c1]52        set_state( this, END );
[b8116cd]53}
54
55int main() {
[200fcb3]56        sout | "Starting";
[b8116cd]57        processor p;
58        for( int i = 0; i < N; i++ ){
[ca278c1]59                dummy_t dummy[4];
[6c7b1e7]60                yield( random( 100 ) );
[b8116cd]61        }
[200fcb3]62        sout | "Stopping";
[6c7b1e7]63}
Note: See TracBrowser for help on using the repository browser.