source: src/tests/sched-ext.c @ 90c4df0

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 90c4df0 was 90c4df0, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Implemented search for external scheduling

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <stdlib>
5#include <thread>
6
7#include <time.h>
8
9static const unsigned long N = 500ul;
10
11#ifndef PREEMPTION_RATE
12#define PREEMPTION_RATE 10_000ul
13#endif
14
15unsigned int default_preemption() {
16        return PREEMPTION_RATE;
17}
18
19monitor global_t {};
20
21global_t globalA;
22
23thread Acceptor {};
24thread Acceptee {};
25
26volatile bool done;
27
28unsigned rand10() {
29        return (unsigned)rand48() % 10;
30}
31
32//----------------------------------------------------------------------------------------------------
33// Acceptor
34void do_notify( global_t * mutex a );
35
36void do_wait( global_t * mutex a ) {
37        sout | "Waiting to accept" | endl;
38        yield( rand10() );
39
40        sout | "Accepting" | endl;
41
42        __acceptable_t acceptable;
43        acceptable.func          = (fptr_t)do_notify;
44        acceptable.count         = 1;
45        acceptable.monitors      = &a;
46        acceptable.run_preaccept = false;
47
48        __accept_internal( 1, &acceptable );
49
50        sout | "Accepted" | endl;
51        yield( rand10() );
52}
53
54void main( Acceptor* this ) {
55        for( int i = 0; i < N; i++ ) {
56                do_wait( &globalA );
57                sout | i | endl;
58        }
59
60        done = true;
61}
62
63//----------------------------------------------------------------------------------------------------
64// Acceptee
65void do_notify( global_t * mutex a ) {
66
67}
68
69void main( Acceptee* this ) {
70        while( !done ) {
71                yield( rand10() );
72                do_notify( &globalA );
73                yield( rand10() );
74        }
75}
76
77//----------------------------------------------------------------------------------------------------
78// Main
79int main(int argc, char* argv[]) {
80        done = false;
81        rand48seed( time( NULL ) );
82        printf("%p\n", &globalA);
83        sout | "Starting" | endl;
84        {
85                Acceptor r;
86                Acceptee e[13];
87
88        }
89        sout | "Done" | endl;
90}
Note: See TracBrowser for help on using the repository browser.