220 likes | 259 Views
Asynchronous Message Passing. EE 524/CS 561 Wanliang Ma 03/08/2000. Mechanisms for Concurrent Programming. Dynamic process creation Semaphores Asynchronous message passing Remote procedure call (RPC) Rendezvous. Call and Send. Call : Synchronous
E N D
Asynchronous Message Passing EE 524/CS 561 Wanliang Ma 03/08/2000
Mechanisms for Concurrent Programming • Dynamic process creation • Semaphores • Asynchronous message passing • Remote procedure call (RPC) • Rendezvous
Call and Send • Call : • Synchronous • two-way communication plus synchronization • Send : • asynchronous • fork a new instance of a proc • one-way communication
Asynchronous Message Passing • Higher level and more powerful than semaphores • Allow processes to communicate • Allow processes to synchronize
Asynchronous Message Passing • Implemented by having processes send messages to and receive messages from operations • The sender continues after sending • asynchronous ( non-blocking) • The receiver delays until receiving and removing a message • synchronous (blocking) • an abbreviation for more general mechanism
Outline of Chapter 9 • Operations as message queues • Semaphores revisited • Data-containing semaphores • Shared Operations
Operations as Message Queues • A new use of operations as message queues • The operation has no corresponding proc • Receive statements service and remove the invocation of an operation from the message queue • The executing process delays if no invocation is present
Operations as Message Queues • How to invoke an operation : send and call • Send invocation: • the invocation is appended to the message queue • the invoker continues after sending • Call invocation : • synchronous form of message passing
Receive statement format receive op_id subscripts ( variable, variable, …)
Examples • Stream merging • Client-Serve models • one client process and one server process • multiple clients and one server process • multiple clients and multiple servers
Semaphores Revisited • Semaphores:abbreviations for operations • a parameterless operation • with send restriction • P statements:abbreviations for send statements • V statements:abbreviations for receive statements
Semaphores Revisited • The two classes of mechanisms are equally efficient • Both are more efficient than a general message passing • semaphores make programs more concise and readable
Data-Containing Semaphores • A generalization of standard semaphores • contain data and a synchronization signal • an unbounded buffer of messages that have been produced and not yet consumed • Declared within a resource or a global • Data is passed as a parameter of a operation
Data-Containing Semaphores • Send statements to append data to the operation’s message queue • receive statements to remove data from the operation’s message queue • synchronization between processes accessing the queue is implicit through their use of send and receive statements
Data-Containing Semaphores • Advantages • saves the programmer from having to write code that explicitly implements a list of free buffers and code that synchronizes access to the list. • Disadvantages • less efficient
Shared Operations • Declared at the top level within a resource or global • can not be declared within processes • If the operation is declared in a resource, only the processes located in the same resource can share the operation • If the operation is declared in a global g, the processes located in g or in any resource or global that imports g can share the operation
Shared Operations • applications • multiple instances of a process can service the same resource operation • server work queues
Shared Operations • Example: • compute the integral of f(x) from 1 to r. • It employs a shared operation, bag, which contains a bag of tasks • Each task represents a sub-interval over which the integral of f is to be approximated