Software Design/Share state by communicating

From Wikiversity
Jump to navigation Jump to search

Why[edit | edit source]

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 | edit source]

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

Related[edit | edit source]

Sources[edit | edit source]

  • 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 | edit source]

  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).