|
|
|
|
|
by cogman10
823 days ago
|
|
That's one example of a lock you might eliminate, but there are plenty of other cases where it's impossible to eliminate locks even while single threaded. Consider, for example, something like this (not real rust, I'm rusty there) lock {
a = foo();
b = io(a).await;
c = bar(b);
}
Eliminating this lock is unsafe because a, b, and c are expected to be updated in tandem. If you remove the lock, then by the time you reach c, a and b may have changed under your feet in an unexpected way because of that await. |
|
I’ve been using nodejs for a decade or so now. Nodejs can also suffer from exactly this problem. In all that time, I think I’ve only reached for a JS locking primitive once.