Changeset 1ed841f


Ignore:
Timestamp:
May 3, 2017, 3:15:05 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
b13fc10
Parents:
c469f43
Message:

Added extra randomness to the barging test

File:
1 edited

Legend:

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

    rc469f43 r1ed841f  
    22#include <kernel>
    33#include <monitor>
     4#include <stdlib>
    45#include <thread>
    56
     
    1213        int counter;
    1314        state_t state;
     15
     16        unsigned short do_signal;
     17        unsigned short do_wait2;
     18        unsigned short do_wait1;
    1419};
    1520
     
    1823        this->counter = 0;
    1924        this->state = BARGE;
     25
     26        this->do_signal = 6;
     27        this->do_wait1  = 1;
     28        this->do_wait2  = 3;
    2029}
    2130
     
    3342        c->counter++;
    3443
     44        if( (c->counter % 1000) == 0 ) sout | c->counter | endl;
     45
    3546        int action = c->counter % 10;
    3647
    37         if( action == 1 || action == 3 ) {
    38                 if(c->state != BARGE) {
    39                         sout | "ERROR Mutual exclusion is inconsistent for wait" | endl;
    40                         abort();
    41                 }
     48        if( action == 0 ) {
     49                c->do_signal = max( ((unsigned)rand48()) % 10, 1);
     50                c->do_wait1 = ((unsigned)rand48()) % (c->do_signal);
     51                c->do_wait2 = ((unsigned)rand48()) % (c->do_signal);
    4252
     53                // if(c->do_wait1 == c->do_wait2) sout | "Same" | endl;
     54        }
     55
     56        if( action == c->do_wait1 || action == c->do_wait2 ) {
    4357                c->state = WAIT;
    4458                wait( &cond );
    4559
    4660                if(c->state != SIGNAL) {
    47                         sout | "ERROR Barging detected" | endl;
     61                        sout | "ERROR Barging detected" | c->counter | endl;
    4862                        abort();
    4963                }
    5064        }
    51         else if( action == 6 ) {
    52                 if(c->state != BARGE) {
    53                         sout | "ERROR Mutual exclusion is inconsistent for signal" | endl;
    54                         abort();
    55                 }
    56 
     65        else if( action == c->do_signal ) {
    5766                c->state = SIGNAL;
    5867
     
    6473        }
    6574
    66         if( (c->counter % 1000) == 0 ) sout | c->counter | endl;
    67         if( c->counter == 100_000 ) c->done = true;
     75        if( c->counter >= 100_000 ) c->done = true;
    6876        return !c->done;
    6977}
     
    8290
    8391int main(int argc, char* argv[]) {
    84         processor p[3];
     92        rand48seed(0);
     93        processor p;
    8594        {
    86                 Threads t[20];
     95                Threads t[17];
    8796        }
    8897}
Note: See TracChangeset for help on using the changeset viewer.