D enters Tiobe top 20

Sebastiaan Koppe mail at skoppe.eu
Fri Nov 8 20:28:32 UTC 2019


On Friday, 8 November 2019 at 17:41:06 UTC, Ola Fosheim Grøstad 
wrote:
> «Structured concurrency» reminds me of rendezvous, i.e. that 
> threads wait for each other at certain points, but less 
> flexible.

What I found insightful is the idea that without structured 
concurrency, functions can just spawn tasks with no obligation to 
wait or clean them up. What you find in practice is that those 
responsibilities are often spread over several functions. The 
result is that even if you have clean code, the end and start of 
those tasks is woven like spaghetti through your code.

Structured concurrency introduces blocks for concurrency, which 
are similar to those introduced by structured programming. You 
can always be sure that when a nursery is exited, all its tasks 
have properly ended.

I for one have had many occasions where I had a rogue task or a 
leaking websocket.

With structured concurrency writing that code is easier, but more 
importantly, reviewing is easier as well.

> I'm not really convinced that a "nursery" is easier to deal 
> with than futures/promises, in the general case, though.

You still have futures with a nursery. It is just that you can't 
leave the nursery block without all concurrent tasks completing, 
timing out or being canceled.


More information about the Digitalmars-d mailing list