News for hackers. Stuff that matters.
Re:V8 adds support for top-level await by kbenson on Tuesday September 24, 2019 @08:31PM (#21066310)
Seems like you should be able to build a lock mechanism fairly simply with async/await, but I agree, it would be nice if it was a built in primitive. It does feel a little silly to implement a lock function when the engine much be using one to support its async functionality in the first place, so you're introducing a lot of inefficiency.
Re:V8 adds support for top-level await by Arelius on Tuesday September 24, 2019 @10:21PM (#21066952)
I don't think it's true that the engine must be using a mutex to support it's async functionality. Or that it is true that an OS mutex will be any more efficient than alternative solutions.

A mutex really can only exist to serialize async code. If you want it serialized that likely means that code shouldn't be async in the first place.

Re:V8 adds support for top-level await by kbenson on Wednesday September 25, 2019 @01:01AM (#21067744)
You're right that it may not be required for the async functionality (especially since lock-free schedulers exist, and the engine is basically a single processor scheduler for processes). I do think it's likely in use other places though, just because it's much easier to write correct code with one.
Re:V8 adds support for top-level await by matharmin on Wednesday September 25, 2019 @02:53AM (#21068386)
Implementing a mutex is very simple and efficient in JavaScript - probably much lower overhead than the Promises itself.