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