jimc
(Jim Crate)
61
You very much don't understand, at least for ruby. Ruby's yield keyword doesn't have anything to do with concurrency, it simply executes the block that was passed.
I've never used C#, but 1 minute of googling and reading the first result showed that yield has nothing to do with concurrency in C#.
Since that didn't take too long, I looked up yield for Javascript. It's used to return a value from a generator function, nothing to do with concurrency.
Python is pretty inscrutable but it appears yield is for generator functions, and while generator functions can be used asynchronously, yield is how the generator function returns a value and has nothing to do with concurrency.
nkbelov
(Nikita Belov)
62
Perhaps to be fair, generators and similar suspending functions can be regarded as a form of concurrency if we go by the dry Wikipedia definition, it's just that they are heavily restricted to pretty much a single suspension point with no fork/join options.
1 Like
crontab
(Hovik Melikyan)
63
I think yield is not very different from Swift's await conceptually, except Swift tries to use the available hardware more efficiently. I.e. the difference is in the implementation although the details of the implementation "leak" in a sense that: languages that don't involve real multithreading let you do whatever you like with data whereas Swift restricts the use of shared data (at compile time) because it knows any chunk of code between suspension points can be executed on any physical thread.
ibex10
64
See @nkbelov's response above.
await doesn't suspend the thread, it suspends the task so that other tasks may run on that thread.
1 Like
ibex10
65
This is by itself turning out to be a kind of tutorial on concurrency. 
Keep it coming.
1 Like
Andropov
(RaĂșl MontĂłn)
66
I liked how this particular topic (how async functions and suspension points work at low level) was addressed in WWDC'24 Explore Swift Performance (10:00 onwards). The main focus of that segment of the video is stack memory, not threads, but I'd say it still works wonders to help build a mental model of what the hardware is doing underneath. And it coincidentally, it explains why an async call is not blocking the caller thread.
2 Likes
clarkezone
(James Clarke)
67
Would love to see a modern from stretch overview rather than the daisy chain of pointers
(Mainly talking about Swift Concurrency here.)
(Please let me know if it is not okay to mention other people's paid resources.)
Not sure if anyone suggested/mentioned already, but Donny Wals Practical Swift Concurrency works for me. The only downside(?) is, it costs $39.99.
If you are looking for free resources, I am sure that there is a lot on the internet, starting from begineer's level, to deep-dive of the design principle of concurrency, tasks, actors, and sendables, like the ones mentioned above.
(Mainly talking about other languages' concurrency here)
Just a side note, in case anyone want to know more about how concurrency works on other programming languages, can check this series of articles:
Structured Concurrency in modern programming languages
1 Like