forked from Java2ArkTS/Java2ArkTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.ets
More file actions
48 lines (41 loc) · 1.13 KB
/
Copy pathIndex.ets
File metadata and controls
48 lines (41 loc) · 1.13 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
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 Counter implements Runnable {
private count: any = getClass('number', 0);
public synArray: any = getSyc();
public sharedType: string = "object";
public increment(): void {
{
SynStart(this['synArray']);
setValues(this.count, getValues(this.count) + 1);
SynEnd(this['synArray']);
}
}
public getCount(): number {
{
SynStart(this['synArray']);
const result = getValues(this.count);
SynEnd(this['synArray']);
return result;
}
}
public run(): void {
for (let i = 0; i < 10000; i++) {
this.increment();
}
}
}
class ThreadExample {
public synArray: any = getSyc();
public sharedType: string = "object";
public static main(args: string[]): void {
const counter = new Counter();
const thread1 = new Thread(counter);
const thread2 = new Thread(counter);
thread1.start();
thread2.start();
}
}