4 ms·
Having more threads doesn't solve inter-thread concurrency like async/await does. With async/await you can achieve concurrency while ensuring there parallelism
by jayd16 5y ago
Having more threads doesn't solve inter-thread concurrency like async/await does. With async/await you can achieve concurrency while ensuring there parallelism as well as is no parallelism (to avoid explicit critical sections).
I don't think you could, for example, use this model of many virtual threads with a traditional GUI framework as designs are still predominately single threaded by nature.
Said another way, cooperative scheduling has its place and will continue to.
I'm excited to see some threaded UI designs shake out of this, though.
- kjeetgill 5y agoYea, it won't solve those things. I think the appeal for languages that already used locks/queues/atomics with their existing threads don't find this to be too, too disruptive.
- gorjusborg 5y agoasync/await doesn't solve anything with concurrency, working on a single thread does. you can do that as a design choice in languages that aren't exclusively single threaded.
- jayd16 5y agoWhat do you mean by this? Async/await provides a standard way to handle message passing between threads, a cleaner syntax than nested callbacks and a lot of other niceties over raw threading. Async/await is in many single and multi-threaded languages so I'm not clear on what you're saying.
- gpderetta 5y agoIf you are using threads you wouldn't use nested callbacks in the first place. In a proper threaded model you can use exactly the same syntax that you would use with async/await (futures, future combinators, message passing what have you) except you do not have to randomly annotate your code with awaits.
- gorjusborg 5y agoWhat I mean is: async/await is just syntactic sugar over promises/futures and those just buy you a way to schedule future computation. The js runtimes schedule all your code on a single thread. It's the fact your code only runs on a single thread that 'solves concurrency' because data races can't happen if one thread of code is allowed to access memory at a time. You can set up the same limitation in a threaded program/language, and people have (see vert.x, clojure STM, and others).
- Spivak 5y agoYou can’t get parallelism with just async/await. Concurrency yes, but as soon as you want to run two async jobs at the same time you take on all the complexities of threads again (because that’s how you actually get parallelism).
- jayd16 5y ago>you take on all the complexities of threads Well no, not _all_ of the complexities because you have await and explicit yielding. It's much easier to pass data from one asynchronous task to another using await than it is to, say, manually code the locks or state machine necessary for the message passing and/or callbacks.
- Spivak 5y agoAwait and explicit yielding do nothing as soon as you want to actually run multiple tasks at the same time in parallel instead of sequentially but interleaved.
- jayd16 5y agoYou can just start the tasks and then await all? At least in C# it also provides a clear system on how to switch scheduling contexts at an await.