【正文】
P2 and P3 receive. ? Who gets the message? ? Solutions ? Allow a link to be associated with at most two processes. ? Allow only one process at a time to execute a receive operation. ? Allow the system to select arbitrarily the receiver. The sender is notified who the receiver was. IPC: Naming ? Properties of indirect munication link ? Link established only if processes share a mon mailbox ? A link may be associated with many processes. ? Each pair of processes may share several munication links. ? Link may be unidirectional or bidirectional. ? Mailbox can be owned by a process or OS. ? create a new mailbox ? send and receive messages through mailbox ? destroy a mailbox IPC: Synchronization ? Blocking and Nonblocking ? Blocking send ? Nonblocking send ? Blocking receive ? Nonblocking receive ? Blocking send and blocking receive ? rendezvous. ? Nonblocking send and blocking receive ? the most mon one. IPC: Buffering ? Queue of messages attached to the link。 while (1) { while (in == out) 。 while (1) { while(((in + 1)%BUFFER_SIZE) == out) 。 item buffer[BUFFER_SIZE]。 few very long CPU bursts. Process scheduling: Context switch ? When CPU switches to another process, the system must save the context of the old process and load the saved context for the new process. ? The context of a process is represented in the PCB of a process. ? To freeze it。 to preserve it。 int in = 0。 /* do nothing */ buffer[in] = nextProduced。 /* do nothing */ nextConsumed = buffer[out]。 implemented in one of three ways. ? Zero capacity – 0 messages Sender must wait for receiver (rendezvous). ? Bounded capacity – finite length of n messages Sender must wait if link full. ? Unbounded capacity – infinite length Sender never waits. IPC: An example: Mach ? Each task has two special mailboxes: the Kernel mailbox and the Notify mailbox. ? Message transferring ? msg_send, msg_receive, msg_rpc. ? Mailbox creation ? port_allocate. IPC: An example: Windows 2K ? LPC: local procedure call facility ? Two types of ports: connection ports and munication ports. ? Messagepassing techniques ? For small messages, to use the port’s message queue as intermediate storage and copies the message from one process to other ? For a large message, t