*Producer :
»get a message block from mayproduce
»put data item in block
»send message to mayconsume
*consumer :
»get a message from mayconsume
»consume data in block
»return empty message block to mayproduce mailbox
Operating System
*Producer :
»get a message block from mayproduce
»put data item in block
»send message to mayconsume
*consumer :
»get a message from mayconsume
»consume data in block
»return empty message block to mayproduce mailbox
–each process wanting to communicate must explicitly name the recipient or sender of the communication
–send and receive primitives defined:
send ( P, message ) : send a message to process P
receive ( Q, message ) : receive a message from process Q
–a link established automatically between every pair of processes that want to communicate
»processes only need to know each other’s identity
–link is associated with exactly two processes
–link is usually bidirectional but can be unidirectional
– Process A Process Bwhile (TRUE) { while (TRUE) { produce an item receive ( A, item ) send ( B, item ) consume item} }
•messages sent to and received from mailboxes (or ports)
–mailboxes can be viewed as objects into which messages placed by processes and from which messages can be removed by other processes
–each mailbox has a unique ID
–two processes can communicate only if they have a shared mailbox
send ( A, message ) : send a message to mailbox Areceive ( A, message ) :
receive a message from mailbox A
- Message passing may be either blocking or non-blocking.
• Blocking is considered synchronous
• Non-blocking is considered asynchronous
- Send and receive primitives may be either blocking or non-blocking.
Once we have multiple processes or threads, it islikely that two or more of them will want tocommunicate with each other
• Process cooperation (i.e., interprocesscommunication) deals with three main issues
– Passing information between processes/threads
– Making sure that processes/threads do not interfere witheach other
– Ensuring proper sequencing of dependent operations
• These issues apply to both processes and theads– Initially we concentrate on shared memory mechanismswe have multilple
>Process executes last statement and asks the operating system to delete it (exit).
>Output data from child to parent (via wait).
>Process’ resources are deallocated by operating system.>Parent may terminate execution of children processes (abort).
>Child has exceeded allocated resources.
>Task assigned to child is no longer required.
>Parent is exiting.
>Operating system does not allow child to continue if its parent terminates.
>Cascading termination.
>Job queue – set of all processes in the system.
>Ready queue – set of all processes residing in main memory, ready and waiting to execute
device
>Device queues – set of processes waiting for an I/O device.
>Processes migrate between the various queues.
>Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.
>Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.
>When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.
>Context-switch time is overhead; the system does no useful work while switching.
>Time dependent on hardware support.
In a multitasking computer system, processes may occupy a variety of states. These distinct states may not actually be recognized as such by the operating system kernel, however they are a useful abstraction for the understanding of processes.
-Information associated with each process.
>Process ID
>Process state
>Program countern CPU registers
>CPU scheduling information
>Memory-management information
>Accounting information
>I/O status information
In computer science, a thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.
On a single processor, multithreading generally occurs by time-division multiplexing (as in multitasking): the processor switches between different threads. This context switching generally happens frequently enough that the user perceives the threads or tasks as running at the same time. On a multiprocessor or multi-core system, the threads or tasks will generally run at the same time, with each processor or core running a particular thread or task. Support for threads in programming languages varies: a number of languages simply do not support having more than one execution context inside the same program executing at the same time.
Examples of such languages include Python, and OCaml, because the parallel support of their runtime support is limited by the use of a central lock, called "Global Interpreter Lock" in Python, "master lock" in Ocaml. Other languages may be limited because they use threads that are user threads, which are not visible to the kernel, and thus cannot be scheduled to run concurrently. On the other hand, kernel threads, which are visible to the kernel, can run concurrently.