How to increment a variable using Linda tuple space

13th November 2022 at 1:19pm
parallel programming tuple

I had to read again the Linda paper to better understand how it works.

Let's say we have one "server" that manages the tuple space and has a variable i. Multiple clients want to increment this variable, how should they do it?

It is actually quite simple: when a client wants to change i, it should first remove i from the tuple space, then performs his calculation and finally put i back in the tuple space, ready for other clients.

// the in statement will remove the index from the tuple space
in("index", ? i) 

// the out statement puts back the index into the tuple space
out("index", i + 1) 

If multiple clients want to access i at the same time, the server pick one non-deterministically.

If a client wants to access i but none is available in the tuple space, the client will wait until i appears.

The true beauty of Linda is that parallel programming can easily be implemented in any language.

Related to


Backlinks: Linda tuple space