Repository navigation
Expand file tree
/
Copy pathIndex.ets
More file actions
54 lines (44 loc) · 1.42 KB
/
Copy pathIndex.ets
File metadata and controls
54 lines (44 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { setValues, getSyc, getClass, getValues, SynStart, SynEnd, addFunc, Runnable, Thread, wait, notify } from './ThreadBridge';
export function sharedWash(threadId: number){
let archetype = Thread.runnableList[threadId];
archetype.run();
}
class Printer {
private currentNumber: any = getClass('number', 1);
private maxNumber: any;
public synArray: any = getSyc();
public sharedType: string = "object";
constructor(maxNumber: number) {
this.maxNumber = getClass('number', maxNumber);
}
public print(): void {
SynStart(this['synArray']);
while (getValues(this.currentNumber) <= getValues(this.maxNumber)) {
console.log(" printed: " + getValues(this.currentNumber));
setValues(this.currentNumber, getValues(this.currentNumber) + 1);
}
SynEnd(this['synArray']);
}
}
class PrintTask implements Runnable {
public synArray: any = getSyc();
public sharedType: string = "object";
private printer: any;
constructor(printer: Printer) {
this.printer = getClass('Printer', printer);
}
run(): void {
getValues(this.printer.print());
}
}
export class PrintNumbers {
public synArray: any = getSyc();
public sharedType: string = "object";
public static main(args: string[]): void {
const printer = new Printer(10);
const thread1 = new Thread(new PrintTask(printer));
const thread2 = new Thread(new PrintTask(printer));
thread1.start();
thread2.start();
}
}