Ignore:
Timestamp:
May 2, 2017, 2:42:14 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
b510ac2
Parents:
5783e94
Message:
  • updated internal scheduler test for multi monitors
  • fixed branding for monitors
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/sched-int-multi.c

    r5783e94 ra933dcf4  
    44#include <thread>
    55
     6enum state_t { WAIT, SIGNAL, BARGE };
     7
    68monitor global_t {};
    79
     10monitor global_data_t {
     11        bool done;
     12        int counter;
     13        state_t state;
     14};
     15
     16void ?{} ( global_data_t * this ) {
     17        this->done = false;
     18        this->counter = 0;
     19        this->state = BARGE;
     20}
     21
     22void ^?{} ( global_data_t * this ) {}
     23
     24global_t globalA;
    825global_t globalB;
    9 global_t globalA;
     26global_data_t globalC;
    1027
    1128condition cond;
    1229
    13 thread Signalee {};
    14 thread Signaler {};
     30thread Threads {};
    1531
    16 void signalee_action( global_t * mutex a, global_t * mutex b ) {
    17         sout | "Waiting All" | endl;
    18         wait( &cond );
    19         sout | "Done waiting" | endl;
     32bool logicC( global_t * mutex a, global_t * mutex b, global_data_t * mutex c ) {
     33        c->counter++;
     34
     35        int action = c->counter % 10;
     36
     37        if( action == 1 || action == 3 ) {
     38                if(c->state != BARGE) {
     39                        sout | "ERROR Mutual exclusion is inconsistent for wait" | endl;
     40                        abort();
     41                }
     42
     43                c->state = WAIT;
     44                wait( &cond );
     45
     46                if(c->state != SIGNAL) {
     47                        sout | "ERROR Barging detected" | endl;
     48                        abort();
     49                }
     50        }
     51        else if( action == 6 ) {
     52                if(c->state != BARGE) {
     53                        sout | "ERROR Mutual exclusion is inconsistent for signal" | endl;
     54                        abort();
     55                }
     56
     57                c->state = SIGNAL;
     58
     59                signal( &cond );
     60                signal( &cond );
     61        }
     62        else {
     63                c->state = BARGE;
     64        }
     65
     66        if( (c->counter % 1000) == 0 ) sout | c->counter | endl;
     67        if( c->counter == 100_000 ) c->done = true;
     68        return !c->done;
    2069}
    2170
    22 void main( Signalee* this ) {
    23         signalee_action( &globalA, &globalB );
     71bool logicB( global_t * mutex a, global_t * mutex b ) {
     72        return logicC(a, b, &globalC);
    2473}
    2574
    26 void signaler_action_inner( global_t * mutex a, global_t * mutex b ) {
    27         sout | "Entering A & B" | endl;
    28         sout | "Signal" | endl;
    29         signal( &cond );
    30         sout | "Leaving  A & B" | endl;
     75bool logicA( global_t * mutex a ) {
     76        return logicB(a, &globalB);
    3177}
    3278
    33 void signaler_action( global_t * mutex a, global_t * b ) {
    34         sout | "Entering A" | endl;
    35         signaler_action_inner( a, b );
    36         sout | "Leaving  A" | endl;
    37 }
    38 
    39 void main( Signaler* this ) {
    40         for(int i = 0; i < 10_000; i++) {
    41                 asm volatile ("" : : : "memory");
    42         }
    43 
    44         signaler_action( &globalA, &globalB );
     79void main( Threads* this ) {
     80        while( logicA(&globalA) ) { yield(); };
    4581}
    4682
    4783int main(int argc, char* argv[]) {
    48         processor p;
     84        processor p[3];
    4985        {
    50                 Signalee a;
    51                 Signaler b;
     86                Threads t[20];
    5287        }
    5388}
Note: See TracChangeset for help on using the changeset viewer.