source: src/tests/sched-ext.c @ 97e3296

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 97e3296 was 97e3296, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

First working implementation of external scheduling... Still lots of testing to do

  • Property mode set to 100644
File size: 1.5 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 = 2_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
26//----------------------------------------------------------------------------------------------------
27// Acceptor
28void do_notify( global_t * mutex a );
29
30void do_wait( global_t * mutex a ) {
31        sout | "Preparing to wait" | endl;
32
33        __acceptable_t acceptable;
34        acceptable.func          = (void_fptr_t)do_notify;
35        acceptable.count         = 1;
36        acceptable.monitors      = &a;
37        acceptable.run_preaccept = false;
38
39        sout | "Waiting for notify" | endl;
40
41        int ret = __accept_internal( 1, &acceptable );
42        sout | "Back from wating, accepted" | ret | endl;
43}
44
45void main( Acceptor* this ) {
46        do_wait( &globalA );
47}
48
49//----------------------------------------------------------------------------------------------------
50// Acceptee
51void do_notify( global_t * mutex a ) {
52        sout | "Notifying" | endl;
53}
54
55void main( Acceptee* this ) {
56        for( volatile int i = 0; i < N; i++ );
57
58        sout | "Call Notify" | endl;
59        do_notify( &globalA );
60}
61
62//----------------------------------------------------------------------------------------------------
63// Main
64int main(int argc, char* argv[]) {
65        processor p;
66        sout | "Starting" | endl;
67        {
68                Acceptor r;
69                Acceptee e;
70        }
71        sout | "Done" | endl;
72}
Note: See TracBrowser for help on using the repository browser.