Skip to content

Commit 1f13497

Browse files
committed
Add timeout before next loop
1 parent 64c7800 commit 1f13497

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

JavaScript/6-blocking.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if (isMainThread) {
5353
setTimeout(() => {
5454
mutex.leave();
5555
console.log(`Leave ${threadId}`);
56-
loop();
56+
setTimeout(loop, 0);
5757
}, 5000);
5858
};
5959
loop();

JavaScript/7-spin-lock.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ if (isMainThread) {
5353
console.log(`Interval ${threadId}`);
5454
}, 500);
5555

56-
const f = async () => {
56+
const loop = async () => {
5757
await mutex.enter();
5858
console.log(`Enter ${threadId}`);
5959
setTimeout(() => {
6060
mutex.leave();
6161
console.log(`Leave ${threadId}`);
62-
f();
62+
setTimeout(loop, 0);
6363
}, 5000);
6464
};
65-
f();
65+
loop();
6666
}

0 commit comments

Comments
 (0)