Skip to content

Commit 1f13497

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

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy