1 / 8

Semantics of Send and Receive

Semantics of Send and Receive. Can be blocking or nonblocking called “synchronous” and “asynchronous” remember: procedure call is synchronous thread fork is asynchronous send, receive both have synchronous and asynchronous implementations. Picture of Synchronous Send, Blocking Receive.

emelda
Download Presentation

Semantics of Send and Receive

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Semantics of Send and Receive • Can be blocking or nonblocking • called “synchronous” and “asynchronous” • remember: • procedure call is synchronous • thread fork is asynchronous • send, receive both have synchronous and asynchronous implementations

  2. Picture of Synchronous Send, Blocking Receive P1 P2 receive Data (blocked) send consume message (blocked) “Go ahead” proceed

  3. Sieve of Eratosthenes:Find primes <= N • Add the number 2 to the set of primes • Create a list of consecutive odd integers • Let p = 3, the first prime number (besides 2) • Count up from p and cross out all multiples of p • Add p to the set of primes • Set p = the smallest number not crossed out • If p <= N, goto step 4; else quit

  4. Sieve of Eratosthenes Using Synchronous Message Passing process Sieve[1] { for j = 3 to N by 2 Sieve[2]!j } process Sieve[i = 2 to Max] { Sieve[i-1]?p print “found a prime”, p while (Sieve[i-1]?num) { if (num mod p != 0) Sieve[i+1]!num } } Uses CSP notation: ? (receive) and ! (send) Terminates in deadlock, but this could be fixed

  5. Picture of Asynchronous Send, Blocking Receive P1 P2 receive Data (blocked) send proceed consume message

  6. Implementation of Asynch. Send/ Blocking Receive • Library must keep track of all channels • one buffer and one semaphore per channel at receiver • On Send(channel, userSpecifiedData) • copy userSpecifiedData into sender-side buffer • (buffer eventually put onto network) • On Receive(channel, userSpecifiedData) • P(thisQueue); copy buffer into userSpecifiedData • On incoming message (specifies channel) • copy message into receiver-side buffer; V(thisQueue)

  7. Tradeoffs in Message Passing • Advantages of blocking send • won’t overwrite message, less buffering • Advantages of nonblocking send • can continue after send (can do other work) • but what if the buffer is full? Block? Fail? • Advantages of blocking receive • know message is received, avoid polling • Advantages of nonblocking receive • can result in fewer copies (buffer posted in advance)

  8. Final Note on Semantics • Other possible semantics exist • Sender also (conceptually) may continue when: • Message is copied out of sender’s address space • Message is put on the network • Message is received at the network device on the receiving end

More Related