Bargitta
Bargitta

Reputation: 2406

Is lock only for multi-thread programming?

JavaScript is single thread and there is no locking syntax there. For other languages like C# or Java which allow multi-thread programming, they have locking mechanisms. But internally does the JavaScript interpreter has some locking mechanism to make sure the operations are atomic?

Upvotes: 0

Views: 81

Answers (1)

Sapikelio
Sapikelio

Reputation: 2604

No. Javascript does not support multi-thread because the browser interprets javascript in a single thread (AFAIK). However you can force concurrency using a while loop with a flag and setTimeout to left the processor to another process.

Upvotes: 1

Related Questions