Software Design/Share state by communicating

Passing state requests through a queue is a way to make the communication between the sender and the receiver independent on the precise timing of the requests, which reduces the complexity of this communication[1] and rules out timing-related concurrency bugs, thus making the code more robust.

Passing changing state through a queue (instead of accessing it at the mutation place) reduces the load on the cache coherence system due to reduced true sharing of the memory lines if there are usually some elements in the queue.[2]

Why not

edit

Organising queues or channels between objects take the system's memory, thus increasing the total memory consumption by the program.

edit

Sources

edit
  • Andrew Gerrand. "Share Memory By Communicating". The Go Blog.
  • David Thomas; Andrew Hunt (2019). The Pragmatic Programmer (20th Anniversary ed.). Addison-Wesley Professional. ISBN 978-0135957059. "Don't hoard state. Pass it around." 

References

edit
  1. Hickey, Rich (October 20, 2011). "Simple Made Easy". If thing A calls thing B you just complected them with "when" and "where". A has to know where the B is, and when that happens is whenever A makes the call. Queues are a way to get rid of this problem.
  2. Martin Thompson; Dave Farley; Michael Barker; Patricia Gee; Andrew Stewart (May 2011). "Disruptor: High performance alternative to bounded queues for exchanging data between concurrent threads" (PDF).