source: src/tests/monitor.c @ f19339e

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationresolv-newwith_gc
Last change on this file since f19339e was 242a902, checked in by Rob Schluntz <rschlunt@…>, 5 years ago

Convert more library files to use references

  • Property mode set to 100644
File size: 653 bytes
RevLine 
[3bb51e1]1#include <fstream>
2#include <kernel>
3#include <monitor>
[4a3334cf]4#include <thread>
[3bb51e1]5
[bcda04c]6monitor global_t {
[3bb51e1]7        int value;
8};
9
[242a902]10void ?{}(global_t & this) {
11        this.value = 0;
[3bb51e1]12}
13
14static global_t global;
15
[ef42b143]16void increment3( global_t * mutex this ) {
17        this->value += 1;
18}
19
20void increment2( global_t * mutex this ) {
21        increment3( this );
22}
23
24void increment( global_t * mutex this ) {
25        increment2( this );
[3bb51e1]26}
27
[bd4d011]28thread MyThread {};
[3bb51e1]29
30void main( MyThread* this ) {
[cb0e6de]31        for(int i = 0; i < 1_000_000; i++) {
[3bb51e1]32                increment( &global );
33        }
34}
35
36int main(int argc, char* argv[]) {
[bcda04c]37        assert( global.__mon.entry_queue.tail != NULL );
[3bb51e1]38        processor p;
39        {
[bd4d011]40                MyThread f[4];
[3bb51e1]41        }
42        sout | global.value | endl;
[242a902]43}
Note: See TracBrowser for help on using the repository browser.