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 a54840b was
80c72a7,
checked in by Thierry Delisle <tdelisle@…>, 7 years ago
|
Remove the pre_accept stuff in external scheduling which was a doomed attempt and handling destructors
|
-
Property mode set to
100644
|
File size:
1.6 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 = 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 | volatile bool done; |
---|
27 | |
---|
28 | unsigned rand10() { |
---|
29 | return (unsigned)rand48() % 10; |
---|
30 | } |
---|
31 | |
---|
32 | //---------------------------------------------------------------------------------------------------- |
---|
33 | // Acceptor |
---|
34 | void do_notify( global_t * mutex a ); |
---|
35 | |
---|
36 | void 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 | |
---|
47 | __accept_internal( 1, &acceptable ); |
---|
48 | |
---|
49 | sout | "Accepted" | endl; |
---|
50 | yield( rand10() ); |
---|
51 | } |
---|
52 | |
---|
53 | void main( Acceptor* this ) { |
---|
54 | for( int i = 0; i < N; i++ ) { |
---|
55 | do_wait( &globalA ); |
---|
56 | sout | i | endl; |
---|
57 | } |
---|
58 | |
---|
59 | done = true; |
---|
60 | } |
---|
61 | |
---|
62 | //---------------------------------------------------------------------------------------------------- |
---|
63 | // Acceptee |
---|
64 | void do_notify( global_t * mutex a ) { |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | void main( Acceptee* this ) { |
---|
69 | while( !done ) { |
---|
70 | yield( rand10() ); |
---|
71 | do_notify( &globalA ); |
---|
72 | yield( rand10() ); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | //---------------------------------------------------------------------------------------------------- |
---|
77 | // Main |
---|
78 | int main(int argc, char* argv[]) { |
---|
79 | done = false; |
---|
80 | rand48seed( time( NULL ) ); |
---|
81 | printf("%p\n", &globalA); |
---|
82 | sout | "Starting" | endl; |
---|
83 | { |
---|
84 | Acceptor r; |
---|
85 | Acceptee e[13]; |
---|
86 | |
---|
87 | } |
---|
88 | sout | "Done" | endl; |
---|
89 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.