source: src/tests/thread.c @ bcda04c

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 bcda04c was cb0e6de, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Threads now use monitor semantics to wait until completion

  • Property mode set to 100644
File size: 940 bytes
Line 
1#include <fstream>
2#include <kernel>
3#include <stdlib>
4#include <thread>
5
6struct First { thread_desc __thrd; signal_once* lock; };
7struct Second { thread_desc __thrd; signal_once* lock; };
8
9DECL_THREAD(First);
10DECL_THREAD(Second);
11
12void ?{}( First * this, signal_once* lock ) { this->lock = lock; }
13void ?{}( Second * this, signal_once* lock ) { this->lock = lock; }
14
15void ^?{}( First  * mutex this ) {}
16void ^?{}( Second * mutex this ) {}
17
18void main(First* this) {
19        for(int i = 0; i < 10; i++) {
20                sout | "First : Suspend No." | i + 1 | endl;
21                yield();
22        }
23        signal(this->lock);
24}
25
26void main(Second* this) {
27        wait(this->lock);
28        for(int i = 0; i < 10; i++) {
29                sout | "Second : Suspend No." | i + 1 | endl;
30                yield();
31        }
32}
33
34
35int main(int argc, char* argv[]) {
36        signal_once lock;
37        sout | "User main begin" | endl;
38        {
39                processor p;
40                {
41                        scoped(First)  f = { &lock };
42                        scoped(Second) s = { &lock };
43                }
44        }
45        sout | "User main end" | endl;
46}
Note: See TracBrowser for help on using the repository browser.