Docsity

Operating System - Deadlock - Notes, Study notes of Operating Systems

Partial preview of the text

Download Operating System - Deadlock - Notes and more Study notes Operating Systems in PDF only on Docsity!

Outline of the last class

  • (^) Safe State
  • (^) Banker’s Algorithm
  • (^) Examples

Topics Covered

  • (^) Deadlock
    • (^) Deadlock Detection
    • (^) Recovery from Deadlock
  • (^) Threads
    • (^) Overview
    • (^) Multithreading Models
    • (^) Threading Issues

 Allow system to enter deadlock state

 Periodically run a deadlock detection

algorithm

 Recover if deadlock is detected

Deadlock Detection

Single Instance of Each

Resource Type

  • (^) Maintain wait-for graph - a cycle implies deadlock (but not vice versa) ResourceAllocation Graph Corresponding waitfor graph

Deadlock Recovery

  • (^) Resource preemption
    • (^) Selecting a victim – minimize cost.
    • (^) Rollback – return to some safe state, restart process for that state.
    • (^) Starvation – same process may always be picked as victim - include number of rollback in cost factor.

Thread

  • (^) A thread is a single sequence stream within in a process.
  • (^) Because threads have some of the properties of processes, they are sometimes called lightweight process.
  • (^) In a process, threads allow multiple executions of streams.
  • (^) In many respect, threads are popular way to improve application through parallelism.

Thread

  • (^) Each thread has its own stack.
  • (^) Stack contains temporary data such as
    • (^) Function parameters
    • (^) Return Addresses
    • (^) Local Variables etc.
  • (^) Since thread will generally call different procedures and thus a different execution history this is why thread needs its own stack.

Thread

  • (^) An operating system that has thread facility, the basic unit of CPU utilization is a thread.
  • (^) A thread has or consists of a
    • (^) program counter (PC),
    • (^) a register set, and
    • (^) a stack space.

Single and Multithreaded

Processes

Benefits of Threads

  • (^) Responsiveness
  • (^) Resource Sharing
  • (^) Economy
  • (^) Utilization of Massive Parallel Architectures

Processes Vs Threads

Differences

  • (^) Unlike processes, threads are not independent of one another.
  • (^) Unlike processes, all threads can access every address in the task.

Processes Vs Threads

  • (^) Unlike processes, thread are design to assist one other.
  • (^) Note that processes might or might not assist one another because processes may originate from different users.

Why Threads?

  • (^) Threads are cheap in the sense that they only need a stack and storage for registers therefore, threads are cheap to create.
  • (^) Threads use very little resources of an operating system in which they are working.
  • (^) That is, threads do not need new address space, global data, program code or operating system resources.

Why Threads?

  • (^) Context switching are fast when working with threads.
  • (^) The reason is that we only have to save and/or restore - (^) PC, - (^) SP & - (^) registers.