���WEEK 5��process Synchronization��
Introduction
Background
Race Conditions
The Critical Section Problem
Solution to Critical-Section Problem
A solution to the critical-section problem must satisfy the following requirements:
1.Mutual Exclusion- If process P1 is executing in its critical section, then no other processes can be executing in their critical sections
2.Progress- If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely
3.Bounded Waiting- A bound, or limit must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted
Semaphore
Introduction to Deadlock
System Model
Deadlock Characterization
Necessary Conditions
Resource-Allocation Graph
Pi
Rj
Pi
Rj
P={P1,P2,P3}
R={R1,R2,R3,R4}
E={P1 R1, P2 R3, R1 P2, R2 P1,R2 P2,R3 P3}
Methods for Handling Deadlocks
Deadlock Prevention
By ensuring that atleast one of these conditions cannot occur can prevent the occurrence of a deadlock
Mutual Exclusion
Hold and Wait
No Preemption
Circular Wait
Deadlock Avoidance
Safe State
Basic Facts
Safe, Unsafe, Deadlock State
Deadlock Detection
Recovery from Deadlock
Breaking deadlock
THREADS
Fig.: Working of single-threaded and multithreaded process
Sl. No. | Process | Thread |
1 | Process is heavy weight or resource intensive. | Thread is light weight, taking lesser resources than a process. |
2 | Process switching needs interaction with operating system. | Thread switching does not need to interact with operating system. |
3 | In multiple processing environments, each process executes the same code but has its own memory and file resources. | All threads can share same set of open files, child processes. |
4 | If one process is blocked, then no other process can execute until the first process is unblocked. | While one thread is blocked and waiting, a second thread in the same task can run. |
5 | Multiple processes without using threads use more resources. | Multiple threaded processes use fewer resources. |
6 | In multiple processes each process operates independently of the others. | One thread can read, write or change another thread's data. |
Difference between Process and Thread
Advantages of Thread
TYPES OF THREADS - KERNEL LEVEL AND USER LEVEL
Threads are implemented in following two ways −
User Level Threads − User managed threads.
Kernel Level Threads − Operating System managed threads acting on kernel, an operating system core.
USER LEVEL THREADS
Advantages
Thread switching does not require Kernel mode privileges.
User level thread can run on any operating system.
Scheduling can be application specific in the user level thread.
User level threads are fast to create and manage.
Disadvantages
In a typical operating system, most system calls are blocking.
Multithreaded application cannot take advantage of multiprocessing.
KERNEL LEVEL THREADS
Advantages
Disadvantages
SL. NO. | User-Level Threads | Kernel-Level Thread |
1 | User-level threads are faster to create and manage. | Kernel-level threads are slower to create and manage. |
2 | Implementation is by a thread library at the user level. | Operating system supports creation of Kernel threads. |
3 | User-level thread is generic and can run on any operating system. | Kernel-level thread is specific to the operating system. |
4 | Multi-threaded applications cannot take advantage of multiprocessing. | Kernel routines themselves can be multithreaded. |
Difference between User-Level & Kernel-Level Thread
MULTITHREADING MODELS
Multithreading models are three types
Many to Many Model
Fig.: Many-to-many Relationship Model
Many to One Model
Fig.: illustrates many-to-one model.
One to One Model
Disadvantage of this model is that creating user thread requires the corresponding Kernel thread.
OS/2, Windows NT and Windows 2000 use one to one relationship model.
Fig.: illustrates one-to-one model
Assignment Questions
2.Write a note on Critical Section Problem.
3. Explain the 3 requirements for the solution to critical-section problem.
4. Write a note on Semaphore.
5. Explain the necessary conditions for deadlock.
6. Explain with an example, Resource allocation Graph.
7. Explain with an example, Resource allocation Graph with no deadlock.
8. How deadlock can be prevented? Explain.
9. Explain, How Deadlock can be avoided.
10. Write a note on safe state.
11. Describe Resource allocation Graph Scheme.
12. Explain the banker’s algorithm.
13. How deadlock can be detected? Explain.
14. How to recover from Deadlock.
15.What is a thread?
16.Compare thread and Process.
17.Explain single threaded and multi -threaded process.
18.List the advantages of thread.
19.With figure, explain user level thread.
20.Compare user level and kernel level thread.
21.Mention advantages and disadvantages of user level threads.
22.Mention advantages and disadvantages of kernel level threads.
23.What is a multithreading model?
24.With neat figures, explain the three types of multithreading models.