Changeset 102a58b


Ignore:
Timestamp:
May 4, 2017, 4:13:36 PM (7 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:
9737ffe
Parents:
4845ae2
Message:

-fixed error in concurrency keywords
-implemented more agressive test for internal scheduling

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r4845ae2 r102a58b  
    246246        //=============================================================================================
    247247        void ConcurrentSueKeyword::visit(StructDecl * decl) {
     248                Visitor::visit(decl);
    248249                if( decl->get_name() == type_name ) {
    249250                        assert( !type_decl );
     
    385386        //=============================================================================================
    386387        void MutexKeyword::visit(FunctionDecl* decl) {
     388                Visitor::visit(decl);           
     389
    387390                std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl );
    388391                if( mutexArgs.empty() ) return;
     
    402405
    403406        void MutexKeyword::visit(StructDecl* decl) {
     407                Visitor::visit(decl);
     408
    404409                if( decl->get_name() == "monitor_desc" ) {
    405410                        assert( !monitor_decl );
     
    504509        //=============================================================================================
    505510        void ThreadStarter::visit(FunctionDecl * decl) {
     511                Visitor::visit(decl);
     512               
    506513                if( ! InitTweak::isConstructor(decl->get_name()) ) return;
    507514
  • src/tests/.expect/concurrent/sched-int.txt

    r4845ae2 r102a58b  
    1 Step 1
    2 Step 2
    3 Step 3
     11000
     22000
     33000
     44000
     55000
     66000
     77000
     88000
     99000
     1010000
     1111000
     1212000
     1313000
     1414000
     1515000
     1616000
     1717000
     1818000
     1919000
     2020000
     2121000
     2222000
     2323000
     2424000
     2525000
     2626000
     2727000
     2828000
     2929000
     3030000
     3131000
     3232000
     3333000
     3434000
     3535000
     3636000
     3737000
     3838000
     3939000
     4040000
     4141000
     4242000
     4343000
     4444000
     4545000
     4646000
     4747000
     4848000
     4949000
     5050000
     5151000
     5252000
     5353000
     5454000
     5555000
     5656000
     5757000
     5858000
     5959000
     6060000
     6161000
     6262000
     6363000
     6464000
     6565000
     6666000
     6767000
     6868000
     6969000
     7070000
     7171000
     7272000
     7373000
     7474000
     7575000
     7676000
     7777000
     7878000
     7979000
     8080000
     8181000
     8282000
     8383000
     8484000
     8585000
     8686000
     8787000
     8888000
     8989000
     9090000
     9191000
     9292000
     9393000
     9494000
     9595000
     9696000
     9797000
     9898000
     9999000
     100100000
     101All waiter done
  • src/tests/sched-int.c

    r4845ae2 r102a58b  
    44#include <thread>
    55
    6 monitor global_t {
    7         int value;
    8 };
     6#define N 100_000
    97
    10 global_t global;
     8enum state_t { WAIT, SIGNAL, BARGE };
     9
     10monitor global_t {};
     11global_t mut;
     12
     13monitor global_data_t;
     14void ?{}( global_data_t * this );
     15void ^?{} ( global_data_t * this );
     16
     17monitor global_data_t {
     18        int counter;
     19        state_t state;
     20} data;
    1121
    1222condition cond;
    1323
    14 thread Signalee {};
    15 thread Signaler {};
     24volatile bool all_done;
    1625
    17 void step1( global_t * mutex this ) {
    18         sout | "Step 1" | endl;
    19         this->value = 1;
    20         wait( &cond );
     26void ?{}( global_data_t * this ) {
     27        this->counter == 0;
     28        this->state = BARGE;
    2129}
    2230
    23 void step2( global_t * mutex this ) {
    24         if( this->value != 1) abort();
     31void ^?{} ( global_data_t * this ) {}
    2532
    26         sout | "Step 2" | endl;
    27         this->value = 2;
    28         signal( &cond );
     33//------------------------------------------------------------------------------
     34// Barging logic
     35void barge( global_data_t * mutex d ) {
     36        d->state = BARGE;
    2937}
    3038
    31 void step3( global_t * mutex this ) {
    32         if( this->value != 2) abort();
     39thread Barger {};
    3340
    34         sout | "Step 3" | endl;
    35         this->value = 3;
    36         signal( &cond );
     41void main( Barger * this ) {
     42        while( !all_done ) {
     43                barge( &data );
     44                yield();
     45        }
    3746}
    3847
    39 void main( Signalee* this ) {
    40         step1( &global );
    41         step3( &global );
     48//------------------------------------------------------------------------------
     49// Waiting logic
     50bool wait( global_t * mutex m, global_data_t * mutex d ) {
     51        wait( &cond );
     52        if( d->state != SIGNAL ) {
     53                sout | "ERROR barging!" | endl;
     54        }
     55
     56        d->counter++;
     57
     58        if( (d->counter % 1000) == 0 ) sout | d->counter | endl;
     59
     60        return d->counter < N;
    4261}
    4362
    44 void main( Signaler* this ) {
    45         for(int i = 0; i < 10_000; i++) {
    46                 asm volatile ("" : : : "memory");
     63thread Waiter {};
     64
     65void main( Waiter * this ) {
     66        while( wait( &mut, &data ) ) { yield(); }
     67}
     68
     69
     70//------------------------------------------------------------------------------
     71// Signalling logic
     72void signal( condition * cond, global_t * mutex a, global_data_t * mutex b ) {
     73        b->state = SIGNAL;
     74        signal( cond );
     75}
     76
     77void logic( global_t * mutex a ) {
     78        signal( &cond, a, &data );
     79
     80        int pauses = (unsigned)rand48() % 10;
     81        for(int i = 0; i < pauses; i++) {
     82                yield();
    4783        }
    4884
    49         step2( &global );
     85        //This is technically a mutual exclusion violation but the mutex monitor protects us
     86        bool running = data.counter < N && data.counter > 0;
     87        if( data.state != SIGNAL && running ) {
     88                sout | "ERROR Eager signal" | data.state | endl;
     89        }
    5090}
    5191
     92thread Signaller {};
     93
     94void main( Signaller * this ) {
     95        while( !all_done ) {
     96                logic( &mut );
     97                yield();
     98        }
     99}
     100
     101//------------------------------------------------------------------------------
     102// Main loop
    52103int main(int argc, char* argv[]) {
    53         assert( global.__mon.entry_queue.tail != NULL );
     104        all_done = false;
    54105        processor p;
    55106        {
    56                 Signalee a;
    57                 Signaler b;
    58         }
    59         if( global.value != 3) abort();
     107                Signaller s;
     108                Barger b[17];
     109                {
     110                        Waiter w[4];
     111                }
     112                sout | "All waiter done" | endl;
     113                all_done = true;
     114        }       
    60115}
Note: See TracChangeset for help on using the changeset viewer.