CSP examples in Julia?


#1

Golang’s concurrency primitives were originally inspired by C. A. R. Hoare’s famous 1978 paper “Communicating sequential processes”, (paper, book).

Here’s a blog post where they talk about it:
https://blog.golang.org/share-memory-by-communicating


This git repo re-implements all of the examples in that original paper in Go, so you can directly compare the ideas to Go’s implementation. It’s really nice!

And here’s the fancy godocs documentation page:


Does anyone know if there’s a similar such repo in Julia?

Julia’s concurrency primitives derive from the same inspiration, and I’d love to see a side-by-side comparison of good julia implementations of these examples!

Some of these could, I think, be expressed more easily in Julia than in Go. For example, I was working on https://tour.golang.org/concurrency/8, and as far as I can tell in Go there’s no great way to alternate reading from two Channels, one then the other:

I eventually settled on this:

func Same(t1, t2 *tree.Tree) bool {
	ch1 := make(chan int)
	ch2 := make(chan int)
	go Walk(t1, ch1)
	go Walk(t2, ch2)
	for ok1,ok2 := true, true; ok1 && ok2; {
		v1, _ok1 := <-ch1
		v2, _ok2 := <-ch2
		if v1 != v2 {return false }
		ok1,ok2 = _ok1,_ok2
	}
	return true
}

But in Julia, of course, you can just zip them!:

function same(t1::Tree, t2::Tree)
    c1 = Channel(c->walk(t1, c))
    c2 = Channel(c->walk(t2, c))
    for (v1,v2) in zip(c1,c2)
        v1 != v2 && return false
    end
    return true
end

Or, even better,

function same(t1::Tree, t2::Tree)
    c1 = Channel(c->walk(t1, c))
    c2 = Channel(c->walk(t2, c))
    return all(isequal.(c1, c2))
end

If no one knows of an existing CSP examples repo in julia, let’s make one!


#2

If no one knows of an existing CSP examples repo in julia, let’s make one!

I’ve started this empty repo where we can collect the examples if no one else has done this yet: