Rss Feed
User Threads
[ ] Thread management done by user-level threads library
[ ] No support from the kernel (The kernel is not aware of the existence of threads)
[ ] Fast to create and manage
[ ] Block all threads for a blocking system call if the kernel is single threaded
[ ] Cannot take advantage of multi-processors
 Three primary thread libraries:
 POSIX Pthreads
 Win32 threads
 Java threads

BENEFITS OF MULTITHREADED PROGRAMMING

BENEFITS

 Responsiveness

 Resource Sharing

 Economy

 Utilization of MP Architectures

INTERPROCESS COMMUNICATION
- - -is a set of techniques for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC techniques are divided into methods for message passing, synchronization, shared memory, and remote procedure calls (RPC). The method of IPC used may vary based on the bandwidth and latency of communication between the threads, and the type of data being communicated. - - -
DIRECT COMMUNICATION
[ ] Sender/receiver refer to each other, as seen before
[ ] Properties of communication link
– Link is established automatically between communicating processes
– Link is associated with exactly two processes
– Exactly one link for every pair of processes
[ ] Communication is symmetric (above) or asymmetric
– send(P,m) // send a message to P
– receive(&id, m) // receive from any process, set id to sender
INDIRECT COMMUNICATION


[ ] Communication via mailboxes (or ports)

[ ] Processes communicate by putting and taking messages in/from mailboxes

– send(A, m) and receive(A,m)

[ ] Properties of communication link

– A link is established between two processes, if they share a mailbox
– Link maybe associated with more than two processes
– A number of different links may exist between any pair of processes; each one a separate mailbox


SYNCHRONIZATION

- - - is timekeeping which requires the coordination of events to operate a system in unison. The familiar conductor of an orchestra serves to keep the orchestra in time. Systems operating with all their parts in synchrony are said to be synchronous or in sync. Some systems may be only approximately synchronized, or plesiochronous. For some applications relative offsets between events need to be determined, for others only the order of the event is important. - - -


[ ] BLOCKING SEND – sender blocked until message is received by receiver (or by mailbox)

[ ] NON - BLOCKING SEND – sending process resumes operation right after sending

[ ] BLOCKING RECEIVE – receiver blocks until message is available

[ ] NON - BLOCKING RECEIVE – receiver retrieves a valid message or returns an error code


BUFFERING

[ ] Zero capacity – queue has length 0, no messages can be outstanding on link, sender blocks for
message exchange

[ ] Bounded capacity – queue has length N, N messages can be in queue at any point in time, sender blocks if queue is full, otherwise it may continue to execute

[ ] Unbounded capacity – queue has infinite length, sender never blocks


PRODUCER COUNTER EXAMPLE


[ ] PRODUCER – generates an integer between 0 and 9 (inclusive), then stores it in a CubbyHole object. To make the synchronization problem more interesting, the Producer sleeps for a random amount of time between 0 and 100 milliseconds before repeating the number generating cycle.

[ ] CONSUMER – consumes all integers from the CubbyHole (the exact same object into which the Producer put the integers in the first place) as quickly as they become available.
Interprocess Communication (IPC)
[ ] Mechanism for processes to communicate and to synchronize their actions.
[ ] Message system – processes communicate with each other without resorting to shared variables.
[ ] IPC facility provides two operations:
* send(message) –message size fixed or variable
* receive(message)
[ ] If P and Q wish to communicate, they need to:
* establish a communication link between them
* exchange messages via send/receive
[ ] Implementation of communication link
* physical (e.g., shared memory, hardware bus) considered later
* logical (e.g., logical properties) now
Cooperating Processes
[ ] Independent process cannot affect or be affected by the execution of another process.
[ ] Cooperating process can affect or be affected by the execution of another process
[ ] Advantages of process cooperation:
* Information sharing
* Computation speed-up
* Modularity
* Convenience
Operations on Processes

Process Creation

[ ] Parent process creates children processes, which, in turn create other processes, forming a tree of processes.
* Resource sharing
[ ] Parent and children share all resources.
[ ] Children share subset of parent’s resources.
[ ] Parent and child share no resources.
* Execution
* Parent and children execute concurrently.
* Parent waits until children terminate.
[ ] Address space
* Child duplicate of parent.
* Child has a program loaded into it.
[ ] UNIX examples
* fork system call creates new process
* fork returns 0 to child , process id of child for parent
* exec system call used after a fork to replace the process’ memory space with a new program.



Process Termination

[ ] 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.
* In Unix, if parent exits children are assigned init as parent
Process Scheduling


Scheduling Queue

[ ] The operating System must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronization amongst process.

[ ] 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 queues – set of processes waiting for an I/O device.

[ ] Processes migrate between the various queues.


Schedulers

[ ] 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.

[ ] Short-term scheduler is invoked very frequently (milliseconds) fi (must be fast).

[ ] Long-term scheduler is invoked very infrequently (seconds, minutes) fi (may be slow).

[ ] The long-term scheduler controls the degree of multiprogramming.

[ ] Processes can be described as either:

* I/O-bound process – spends more time doing I/O than computations, many short CPU bursts.

* CPU-bound process – spends more time doing computations; few very long CPU bursts.


Context Switch

[ ] 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.