Roy Diagram

.
2 min readJun 27, 2016

--

In Computer Science, Roy diagrams are pictorial representations of the concurrency model describing the behavior of go-routines and channels. Roy diagrams give a simple visualisation of what would otherwise be a rather arcane and abstract program.

Sequential

Fundamentally, it begins with a pair of functions, which algorithms in it are to be executed sequentially. Communication between functions via a channel.

fundamental blocks

In diagram above, it is important to highlight that functions are arranged in sequential order, fn(i) executes before fn(i+1).

#channel #sequential #function

Concurrent

In Go, each concurrently executing activity is called a go-routine. In a concurrent program with two or more go-routines, calls to both functions can be active at the same time. In other words, order of executions is radically unknown.

go-ed fn(i)

When we go-ed the first function, its entire chain(sequential), started itself down to the last bit, are duplicated, and independently runs in parallel.

Example (cake shop)

cake-shop illustrated with Roy Diagram

Note that, 1 worker: 1 go-routine, n workers: n go-routines. Notice that for n workers: from ICING till the last process, INSCRIBE are duplicated and runs independently by number of n.

References

Repository below demonstrates concurrency modal in processes arranged in sequential order: bake -> ice ->inscribe.

--

--

.
.

Written by .

Engineer & runner based in Bangkok, Thailand.

No responses yet