We can use this term to describe methods and method calls: if a method is a blocking method, then a call to that method can block, waiting until some event occurs before it returns to the caller. We saw in Locks and Synchronization that a thread blocks trying to acquire a lock until the lock has been released by its current owner.īlocking means that a thread waits (without doing further work) until an event occurs. In the next concurrency reading we’ll see how to implement message passing between client/server processes over the network. 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. We’ll use blocking queues (an existing threadsafe type) to implement message passing between threads within a process. We’ll discuss in this reading how to implement message passing within a single process. Message passing also shares only immutable objects (the messages) between modules, whereas shared memory requires sharing mutable objects, which we have already seen 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 thread 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.
0 Comments
Leave a Reply. |