News for hackers. Stuff that matters.
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by jayd16 on Monday May 02, 2022 @03:17PM (#31239550)
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.

Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by kjeetgill on Monday May 02, 2022 @04:47PM (#31240720)
Yea, 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.
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by Spivak on Monday May 02, 2022 @09:29PM (#31243266)
You 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).
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by jayd16 on Monday May 02, 2022 @10:03PM (#31243572)
>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.

Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by Spivak on Tuesday May 03, 2022 @12:14AM (#31244532)
Await 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.
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by jayd16 on Tuesday May 03, 2022 @10:49AM (#31249051)
You 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.
Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by gorjusborg on Monday May 02, 2022 @06:22PM (#31241789)
async/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.

Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by jayd16 on Monday May 02, 2022 @10:06PM (#31243604)
What 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.

Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by gorjusborg on Wednesday May 04, 2022 @02:55PM (#31264417)
What 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).

Re:JEP proposed to target JDK 19: 425: Virtual Threads (Prev... by gpderetta on Tuesday May 03, 2022 @08:54AM (#31247674)
If 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.