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 e50e9ff 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 | |
---|
9 | static const unsigned long N = 2_500ul; |
---|
10 | |
---|
11 | #ifndef PREEMPTION_RATE |
---|
12 | #define PREEMPTION_RATE 10_000ul |
---|
13 | #endif |
---|
14 | |
---|
15 | unsigned int default_preemption() { |
---|
16 | return PREEMPTION_RATE; |
---|
17 | } |
---|
18 | |
---|
19 | monitor global_t {}; |
---|
20 | |
---|
21 | global_t globalA; |
---|
22 | |
---|
23 | thread Acceptor {}; |
---|
24 | thread Acceptee {}; |
---|
25 | |
---|
26 | //---------------------------------------------------------------------------------------------------- |
---|
27 | // Acceptor |
---|
28 | void do_notify( global_t * mutex a ); |
---|
29 | |
---|
30 | void 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 | |
---|
45 | void main( Acceptor* this ) { |
---|
46 | do_wait( &globalA ); |
---|
47 | } |
---|
48 | |
---|
49 | //---------------------------------------------------------------------------------------------------- |
---|
50 | // Acceptee |
---|
51 | void do_notify( global_t * mutex a ) { |
---|
52 | sout | "Notifying" | endl; |
---|
53 | } |
---|
54 | |
---|
55 | void 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 |
---|
64 | int 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.