3 ms·
Isn't that how nearly all multi-threaded code is written? Wouldn't the only other option be fire-and-forget? I've been writing code like this is nearly every la
by pkulak 6y ago
Isn't that how nearly all multi-threaded code is written? Wouldn't the only other option be fire-and-forget? I've been writing code like this is nearly every language I've ever used for decades.
Are you talking about the actual fork() function, instead of, say, spawning inside a loop explicitly?
- dragontamer 6y ago> Isn't that how nearly all multi-threaded code is written Producer-consumer queues say otherwise. As does Async. There's also message-passing. There's also thread-pools. Task-based programming doesn't wait for the tasks to finish. So without the "join", you don't have an easy synchronization point to rely upon, and have to use explicit locks for synchronization. ------ Producer - consumer can't work with fork/join, because there's no "join" at all! The producer keeps producing, and the consumers just keep consuming. Async is... a tangled mess. I'm pretty sure its just the modern "unstructured goto" style of spaghetti that has been rediscovered. Yeah, its super-efficient, but no, its not really easy to program. Task-based parallelism is probably my next favorite style. Fork-join is super easy, but the join causes a significant waiting period and underutilization of the processor. Task-based provides more flexibility (at the cost of a little bit more complexity). ------ There's a ton of other models of parallelism. But fork-join seems to be the methodology that more and more work is being focused on.
- leephillips 6y agoAs I mention in the article, Julia has task-based parellelism now, with a @spawn macro.
- dragontamer 6y agoThat's wonderful to hear! I'm looking into it: and it looks like "Stupid Fibonacci" proves that its working in Julia (https://julialang.org/blog/2019/07/multithreading/ https://julialang.org/blog/2019/07/multithreading/). Task-based parallelism is fraught with more overhead than other patterns. But it really is a powerful construct: converting recursive ideas into multithreaded concepts rather easily.
- nbadg 6y ago> Async is... a tangled mess. I'm pretty sure its just the modern "unstructured goto" style of spaghetti that has been rediscovered. Yeah, its super-efficient, but no, its not really easy to program. That's not inherent to async though, just a property of the implementations that have seen widespread adoption. There's nothing stopping async from implementing the same process tree semantics; in fact, there's at least one high-level async library that does exactly that (python-trio, https://trio.readthedocs.io/en/stable/ https://trio.readthedocs.io/en/stable/)