4 ms·
You avoid race conditions of writing to the same variable but you still can't avoid race conditions where the critical section is longer than 1 statement e.g.
by trinovantes 5y ago
You avoid race conditions of writing to the same variable but you still can't avoid race conditions where the critical section is longer than 1 statement
e.g. in JS:
foo = await fetch()
bar = await fetch()
doSomething(foo, bar)
You can't be certain foo isn't modified while the second fetch is executing (assuming foo is globally scoped)
- wonnage 5y agoThere’s still an important difference in that you’re yielding control explicitly by using await, instead of being preemptable everywhere. That’s good enough in most cases.
- ninkendo 5y agoThe problem with function coloring is that it tends to proliferate throughout APIs (since you need to be async to call async), so as things evolve you find yourself needing to await the majority of function calls… this makes it kind of tough to avoid awaiting during critical paths. That said I still agree that it’s easier to manage than Threads, but something tells me we’re still going to want structured-concurrency versions of the common primitives like rw locks and mutexes, even in async environments.