DOC PREVIEW
LSU CSC 4103 - Processes and Threads

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

11CSC 4103 - Operating SystemsSpring 2007Tevfik KoşarLouisiana State UniversityJanuary 25th, 2007Lecture - IV- Processes & Threads2Roadmap• Processes– Process Termination– Producer-Consumer Problem– Inter-process Communication• Threads– Threads vs Processes– Multi-threading Models– Threading Issues23Process 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– If parent is exiting• Some operating system do not allow child to continue if its parent terminates– All children terminated - cascading termination4Cooperating 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– Convenience35Producer-Consumer Problem• Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process– unbounded-buffer places no practical limit on the size of the buffer– bounded-buffer assumes that there is a fixed buffer size6Bounded-Buffer – Shared-Memory Solution• Shared data#define BUFFER_SIZE 10Typedef struct {. . .} item;item buffer[BUFFER_SIZE];int in = 0;int out = 0;• Solution is correct, but can only use BUFFER_SIZE-1 elements47Bounded-Buffer – Insert() Methodwhile (true) {/* Produce an item */while (((in = (in + 1) % BUFFER SIZE count) == out); /* do nothing -- no free buffers */buffer[in] = item;in = (in + 1) % BUFFER SIZE;{8Bounded Buffer – Remove() Methodwhile (true) {while (in == out); // do nothing -- nothing to consume// remove an item from the bufferitem = buffer[out];out = (out + 1) % BUFFER SIZE;return item;{59Interprocess Communication (IPC)• Mechanism for processes to communicate and to synchronize their actions• Shared Memory: by using the same address space and shared variables• Message Passing: processes communicate with each other without resorting to shared variables• Message Passing 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/receive10Communications Models a) Message Passing b) Shared Memory611Message Passing – direct communication• Processes must name each other explicitly:– send (P, message) – send a message to process P– receive(Q, message) – receive a message from process Q• Properties of communication link– Links are established automatically– A link is associated with exactly one pair of communicating processes– Between each pair there exists exactly one link– The link may be unidirectional, but is usually bi-directional• Symmetrical vs Asymmetrical direct communication– send (P, message) – send a message to process P– receive(id, message) – receive a message from any process• Disadvantage of both: limited modularity, hardcoded12Message Passing - indirect communication• Messages are directed and received from mailboxes (also referred to as ports)– Each mailbox has a unique id– Processes can communicate only if they share a mailbox• Primitives are defined as:send(A, message) – send a message to mailbox Areceive(A, message) – receive a message from mailbox A713Indirect Communication (cont.)• Operations– create a new mailbox– send and receive messages through mailbox– destroy a mailbox• Properties of communication link– Link established only if processes share a common mailbox– A link may be associated with many processes– Each pair of processes may share several communication links– Link may be unidirectional or bi-directional14Indirect Communication (cont.)• Mailbox sharing– P1, P2, and P3share mailbox A– P1, sends; P2and P3receive– 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. Sender is notified who the receiver was.815Synchronization• Message passing may be either blocking or non-blocking• Blocking is considered synchronous– Blocking send has the sender block until the message is received– Blocking receive has the receiver block until a message is available• Non-blocking is considered asynchronous– Non-blocking send has the sender send the message and continue– Non-blocking receive has the receiver receive a valid message or null16Buffering• Queue of messages attached to the link; implemented in one of three ways1. Zero capacity – 0 messagesSender must wait for receiver (rendezvous)2. Bounded capacity – finite length of n messagesSender must wait if link full3. Unbounded capacity – infinite length Sender never waits917Threads18Motivation• In certain cases, a single application may need to run several tasks at the same time– Create a new process for each task• Time consuming– Use a single process with multiple threads1019Single and Multithreaded Processes20Multi-process modelAB CD EParent processChild processesProcess Spawning:Process creation involves the following four main actions:• setting up the process control block, • allocation of an address space and• loading the program into the allocated address space and • passing on the process control block to the scheduler1121Multi-thread modelThread Spawning:• Threads are created within and belonging to processes• All the threads created within one process share the resources of the process including the address space• Scheduling is performed on a per-thread basis. • The thread model is a finer grain scheduling model than the process model• Threads have a similar lifecycle as the processes and will be managed mainly in the same way as processes areProcessThreads22Threads vs Processes• Heavyweight Process = Process• Lightweight Process = ThreadAdvantages (Thread vs. Process):• Much quicker to create a thread than a process• Much quicker to switch between threads than to switch between processes•


View Full Document

LSU CSC 4103 - Processes and Threads

Download Processes and Threads
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Processes and Threads and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Processes and Threads 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?