Great meeting! Amazingly, we got through the whole chapter. We spent a considerable amount of time trying to understand the operation of the first parallel version of the file finder, specifically:
- understanding how it satisfied the desired property of determinism, so that if something was found or an exception was thrown in the leftmost subdirectory, nothing that happened in any other subdirectory would matter to the result, even if it threw an exception,
- how the hierarchy of lists of Asyncs was built (it turns out there’s one list per directory),
- how the foldr over subfind worked (it was easiest to understand it as continuation-passing style, with ‘inner’ representing the continuation)
- the order of operations - i.e., what was happening concurrently, and which threads were waiting on which.
It turned out that if the leftmost subdirectory took a long time to search, then even if another subdirectory finished first, we still had to wait for the leftmost one to complete, in order to satisfy the desired deterministic semantics of preferring the leftmost result.
The rest of the chapter was pretty straightforward, albeit interesting, after that.
In the end it seemed like you may as well use ParIO for most impure parallel computations, since it does all kinds of fancy load balancing for you. The only caveat is that it doesn’t handle exceptions well.
The chapter ended with a challenge to solve this problem - to handle the exceptions well by layering a bit of code on top of ParIO. The author provides a solution in findpar5.hs, but why not give it a go yourself first?