Why DataFlow variables can only be assigned once

514 views Asked by At

I am exploring GPars(Groovy Parallel System) library these days and I came across DataFlow variables. The documentation says Dataflow variables can only be assigned once. However I could not find a reason for this restriction.

Can somebody tell me why Dataflow variables in GPars be assigned only once?

2

There are 2 answers

0
gfour On

In dataflow programming variables are write-once and this is how they synchronize the code that uses (consumes) their value - it is this flow of data that guides execution.

A nice book about programming in general and dataflow concurrency in particular is Concepts, Techniques, and Models of Computer Programming, where you can learn more about the way dataflow synchronization variables are meant to be used (using the Oz language).

On the other hand, if you could assign more than one values to a variable, then each time the value was written, its consumers should be notified - this sounds more like message-passing.

0
Dierk On

Since a DataflowVariable can never change it's value, you cannot have any race condition on it. You can even do non-blocking writes and thus be very efficient and deadlock-free by design. After the initial assignment, you can even do non-blocking reads.