Ignore:
Timestamp:
Aug 22, 2017, 1:44:12 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:
80c72a7
Parents:
e50e9ff
Message:

Implemented search for external scheduling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/sched-ext.c

    re50e9ff r90c4df0  
    77#include <time.h>
    88
    9 static const unsigned long N = 2_500ul;
     9static const unsigned long N = 500ul;
    1010
    1111#ifndef PREEMPTION_RATE
     
    2424thread Acceptee {};
    2525
     26volatile bool done;
     27
     28unsigned rand10() {
     29        return (unsigned)rand48() % 10;
     30}
     31
    2632//----------------------------------------------------------------------------------------------------
    2733// Acceptor
     
    2935
    3036void do_wait( global_t * mutex a ) {
    31         sout | "Preparing to wait" | endl;
     37        sout | "Waiting to accept" | endl;
     38        yield( rand10() );
     39
     40        sout | "Accepting" | endl;
    3241
    3342        __acceptable_t acceptable;
    34         acceptable.func          = (void_fptr_t)do_notify;
     43        acceptable.func          = (fptr_t)do_notify;
    3544        acceptable.count         = 1;
    3645        acceptable.monitors      = &a;
    3746        acceptable.run_preaccept = false;
    3847
    39         sout | "Waiting for notify" | endl;
     48        __accept_internal( 1, &acceptable );
    4049
    41         int ret = __accept_internal( 1, &acceptable );
    42         sout | "Back from wating, accepted" | ret | endl;
     50        sout | "Accepted" | endl;
     51        yield( rand10() );
    4352}
    4453
    4554void main( Acceptor* this ) {
    46         do_wait( &globalA );
     55        for( int i = 0; i < N; i++ ) {
     56                do_wait( &globalA );
     57                sout | i | endl;
     58        }
     59
     60        done = true;
    4761}
    4862
     
    5064// Acceptee
    5165void do_notify( global_t * mutex a ) {
    52         sout | "Notifying" | endl;
     66
    5367}
    5468
    5569void main( Acceptee* this ) {
    56         for( volatile int i = 0; i < N; i++ );
    57 
    58         sout | "Call Notify" | endl;
    59         do_notify( &globalA );
     70        while( !done ) {
     71                yield( rand10() );
     72                do_notify( &globalA );
     73                yield( rand10() );
     74        }
    6075}
    6176
     
    6378// Main
    6479int main(int argc, char* argv[]) {
    65         processor p;
     80        done = false;
     81        rand48seed( time( NULL ) );
     82        printf("%p\n", &globalA);
    6683        sout | "Starting" | endl;
    6784        {
    6885                Acceptor r;
    69                 Acceptee e;
     86                Acceptee e[13];
     87
    7088        }
    7189        sout | "Done" | endl;
Note: See TracChangeset for help on using the changeset viewer.