Instead of using blocking operations, we will provide a callback function to receive messages. Some of the operations of a blocking queue are blocking in the sense that calling the operation blocks the progress of the thread until the operation can return a result.īlocking makes writing code easier, but it also means we must continue to contend with bugs that cause deadlock.įor message passing between TypeScript workers, we’ll use a channel abstraction for sending and receiving messages. We’ll use blocking queues to implement message passing between Java threads. We will start with Java, because it makes the mechanism of message passing more explicit. We’ll discuss in this reading how to implement message passing in two contexts: Message passing also shares only immutable objects (the messages) between modules, whereas shared memory requires sharing mutable objects, which even in non-concurrency programming can be a source of bugs. The implicit interaction of shared memory can too easily lead to inadvertent interaction, sharing and manipulating data in parts of the program that don’t know they’re concurrent and aren’t cooperating properly in the concurrency safety strategy. In message-passing, concurrent modules interact explicitly, by passing messages through the communication channel, rather than implicitly through mutation of shared data. The message passing model has several advantages over the shared memory model, which boil down to greater safety from bugs. That communication channel might connect different computers over a network, as in some of our initial examples: web browsing, instant messaging, etc. In the message passing model, concurrent modules interact by sending immutable messages to one another over a communication channel.
0 Comments
Leave a Reply. |