source: src/tests/sched-ext.c@ e2b17a4

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since e2b17a4 was 310e5b7, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Fix some issues with waitfor... it appears to work!

  • 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
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
47 __waitfor_internal( 1, &acceptable );
48
49 sout | "Accepted" | endl;
50 yield( rand10() );
51}
52
53void 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
64void do_notify( global_t * mutex a ) {
65
66}
67
68void main( Acceptee* this ) {
69 while( !done ) {
70 yield( rand10() );
71 do_notify( &globalA );
72 yield( rand10() );
73 }
74}
75
76//----------------------------------------------------------------------------------------------------
77// Main
78int 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.