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 17f22e78 was bcda04c, checked in by Thierry Delisle <tdelisle@…>, 8 years ago |
Fixed autogen constructors for concurrent sues
|
-
Property mode
set to
100644
|
File size:
960 bytes
|
Line | |
---|
1 | #include <fstream>
|
---|
2 | #include <kernel>
|
---|
3 | #include <monitor>
|
---|
4 | #include <thread>
|
---|
5 |
|
---|
6 | static int global12, global23, global13;
|
---|
7 |
|
---|
8 | monitor monitor_t {};
|
---|
9 |
|
---|
10 | static monitor_t m1, m2, m3;
|
---|
11 |
|
---|
12 | void increment( monitor_t * mutex p1, monitor_t * mutex p2, int * value ) {
|
---|
13 | *value += 1;
|
---|
14 | }
|
---|
15 |
|
---|
16 | struct MyThread {
|
---|
17 | thread_desc __thrd;
|
---|
18 | int target;
|
---|
19 | };
|
---|
20 |
|
---|
21 | DECL_THREAD(MyThread);
|
---|
22 |
|
---|
23 | void ?{}( MyThread * this, int target ) {
|
---|
24 | this->target = target;
|
---|
25 | }
|
---|
26 |
|
---|
27 | void ^?{}( MyThread * mutex this ) {}
|
---|
28 |
|
---|
29 | void main( MyThread* this ) {
|
---|
30 | for(int i = 0; i < 1000000; i++) {
|
---|
31 | choose(this->target) {
|
---|
32 | case 0: increment( &m1, &m2, &global12 );
|
---|
33 | case 1: increment( &m2, &m3, &global23 );
|
---|
34 | case 2: increment( &m1, &m3, &global13 );
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | int main(int argc, char* argv[]) {
|
---|
40 | processor p;
|
---|
41 | {
|
---|
42 | scoped(MyThread) * f[6];
|
---|
43 | for(int i = 0; i < 6; i++) {
|
---|
44 | f[i] = ((scoped(MyThread) *)malloc()){ i % 3 };
|
---|
45 | }
|
---|
46 |
|
---|
47 | for(int i = 0; i < 6; i++) {
|
---|
48 | delete( f[i] );
|
---|
49 | }
|
---|
50 | }
|
---|
51 | sout | global12 | global23 | global13 | endl;
|
---|
52 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.