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
57 lines (46 loc) · 1.59 KB
/
Copy pathIndex.ets
File metadata and controls
57 lines (46 loc) · 1.59 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
55
56
57
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 InconsistentReadDemo {
count: any = getClass('number', 1);
public synArray: any = getSyc();
public sharedType: string = "object";
public static main(args: string[]) {
const demo = new InconsistentReadDemo();
const thread = new Thread(new ConcurrencyCheckTask(demo));
thread.start();
while (true) {
setValues(demo.count, getValues(demo.count) + 1);
}
}
}
class ConcurrencyCheckTask implements Runnable {
private demo: InconsistentReadDemo;
constructor(demo: InconsistentReadDemo) {
this.demo = demo;
}
public run() {
// Implement the logic for the task
}
}
class ConcurrencyCheckTask implements Runnable {
public synArray: any = getSyc();
public sharedType: string = "object";
private demo: any = getClass('InconsistentReadDemo', new InconsistentReadDemo());
constructor(demo: InconsistentReadDemo) {
setValues(this.demo, demo);
}
run(): void {
let c = 0;
for (let i = 0; ; i++) {
const c1 = getValues(this.demo.count);
const c2 = getValues(this.demo.count);
if (c1 !== c2) {
c++;
console.error(`Inconsistent read observed!! Check time=${i + 1}, Occurrence=${c} (${(c / (i + 1) * 100)}%), 1=${c1}, 2=${c2}`);
}
}
}
}