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 3f414ef was 2781e65, checked in by Thierry Delisle <tdelisle@…>, 9 years ago |
added support for acquiring multiple monitors at once
|
-
Property mode
set to
100644
|
File size:
754 bytes
|
Rev | Line | |
---|
[3bb51e1] | 1 | #include <fstream>
|
---|
| 2 | #include <kernel>
|
---|
| 3 | #include <monitor>
|
---|
| 4 | #include <threads>
|
---|
| 5 |
|
---|
| 6 | struct global_t {
|
---|
| 7 | int value;
|
---|
[cc7f4b1] | 8 | __monitor_t m;
|
---|
[3bb51e1] | 9 | };
|
---|
| 10 |
|
---|
| 11 | void ?{}(global_t * this) {
|
---|
| 12 | this->value = 0;
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | static global_t global;
|
---|
| 16 |
|
---|
| 17 | void increment( /*mutex*/ global_t * this ) {
|
---|
[2781e65] | 18 | __monitor_t * mon = &this->m;
|
---|
| 19 | monitor_guard_t g1 = { &mon };
|
---|
[cc7f4b1] | 20 | {
|
---|
[2781e65] | 21 | monitor_guard_t g2 = { &mon };
|
---|
[cc7f4b1] | 22 | {
|
---|
[2781e65] | 23 | monitor_guard_t g3 = { &mon };
|
---|
[cc7f4b1] | 24 | this->value += 1;
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
[3bb51e1] | 27 | }
|
---|
| 28 |
|
---|
| 29 | struct MyThread { thread t; };
|
---|
| 30 |
|
---|
| 31 | DECL_THREAD(MyThread);
|
---|
| 32 |
|
---|
| 33 | void ?{}( MyThread * this ) {}
|
---|
| 34 |
|
---|
| 35 | void main( MyThread* this ) {
|
---|
| 36 | for(int i = 0; i < 1000000; i++) {
|
---|
| 37 | increment( &global );
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | int main(int argc, char* argv[]) {
|
---|
| 42 | assert( global.m.entry_queue.tail != NULL );
|
---|
| 43 | processor p;
|
---|
| 44 | {
|
---|
| 45 | scoped(MyThread) f[4];
|
---|
| 46 | }
|
---|
| 47 | sout | global.value | endl;
|
---|
| 48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.