A simple model of concurrency

I was playing with a little toy language back in the late 90's/early 2000's that I called List, and I thought the core idea might be helpful as we think about Swift's core concurrency abstractions...

Note: I am not proposing any syntax, just describing a concept to consider how/if it might be helpful in Swift-land...

The main idea in List was that imperative programs are just a list of steps that need to be performed in order:

Make some cookies:
1) Mix ingredients in bowl
2) Place small balls of mixture onto a cookie sheet
3) Turn on oven to 350°
4) Place cookie sheet in oven
5) Wait 20 minutes
6) Take cookies out of oven
7) Turn off the oven

Now in modern languages, we don't number the steps explicitly, but the order of the steps really matters. They may depend on each other (e.g. we have to mix the batter before placing it on the cookie sheet) or switching the order may result in a different state (e.g. If we turn off the oven before turning it on, we still get cookies, but we also burn down the house)

There are also times where the order of a list of things doesn't really matter... all that matters is that all of the things get done.

Today's todo list:
• Go to bank
• Wash car
• Pick up dry cleaning

Here the order doesn't really matter because the individual items of the list aren't dependent on one another. If we find ourselves near the dry cleaners before the bank, we can pop in and pick it up first.

The core idea behind List was that most algorithms can be represented as nested lists of either ordered or unordered items*. The compiler was free to either re-order or parallelize the unordered lists, but it would make sure all of the items had completed before moving on:

Do this first
Then this second
    • This item is done after the second one
    • This item is parallelized with the one before it
    • This item is parallelized and has multiple steps
         Another ordered step in the item above
         Another ordered step in the item above
This item will only happen after all the parallel ones complete

I'm not sure what the syntax would be for Swift, but the idea of "Here is a number of things which need to get done. I don't care about the order, but I want all of them to complete before moving" is one that comes up A LOT in application programming, and I feel like it is missing from the async discussion.

Sure, it is possible, but right now you have to use things like dispatch groups. It would be nice to have a minimal syntax which identifies a block of things to dispatch in this way...

* For the curious, you also needed a concept of parallel or ordered loops, which essentially acted like map and reduce respectively (with the possibility of a void return if you just wanted side effects). But that isn't really relevant to the point I was making above...


I recommend taking a read of Notes on Structured Concurrency, which you may find contain concepts and discussions very similar to your ideas. This document has been explicitly referenced by the core team multiple times, and will be a relevant part of any concurrency designs in Swift.