source: src/tests/thread.c @ 7d49b72

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 7d49b72 was 242a902, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Convert more library files to use references

  • Property mode set to 100644
File size: 759 bytes
RevLine 
[0c92c9f]1#include <fstream>
2#include <kernel>
3#include <stdlib>
[4a3334cf]4#include <thread>
[0c92c9f]5
[f3c1737]6thread First  { semaphore* lock; };
7thread Second { semaphore* lock; };
[0c92c9f]8
[242a902]9void ?{}( First & this, semaphore* lock ) { this.lock = lock; }
10void ?{}( Second & this, semaphore* lock ) { this.lock = lock; }
[0c92c9f]11
12void main(First* this) {
13        for(int i = 0; i < 10; i++) {
14                sout | "First : Suspend No." | i + 1 | endl;
15                yield();
16        }
[f3c1737]17        V(this->lock);
[0c92c9f]18}
19
20void main(Second* this) {
[f3c1737]21        P(this->lock);
[0c92c9f]22        for(int i = 0; i < 10; i++) {
23                sout | "Second : Suspend No." | i + 1 | endl;
24                yield();
25        }
26}
27
28
29int main(int argc, char* argv[]) {
[f3c1737]30        semaphore lock = { 0 };
[0c92c9f]31        sout | "User main begin" | endl;
32        {
[ee897e4b]33                processor p;
[0c92c9f]34                {
[bd4d011]35                        First  f = { &lock };
36                        Second s = { &lock };
[0c92c9f]37                }
38        }
39        sout | "User main end" | endl;
[242a902]40}
Note: See TracBrowser for help on using the repository browser.