Notes - MIECT
Sistemas De Operação
Notes - MIECT
Sistemas De Operação
  • Sistemas de Operação
  • Processes in Unix/Linux
    • Process
    • Multiprocessing vs. Multiprogramming
    • Processes in Unix
    • Execution of a C/C++ program
  • Introduction to operating systems
    • Global view
    • Evolution of computational systems
    • Key topics
  • Semaphores and Shared memory
    • Concepts
    • Semaphores
    • Shared memory
    • Unix IPC primitives
  • Threads, mutexes and condition variables in Unix/Linux
    • Threads
      • In linux
    • Monitors
    • Unix IPC primitives
  • Processes
    • Process
      • Diagrams
    • Process control table
    • Context switching
    • Threads
  • Processor Scheduling
    • Processor Scheduler
    • Short-term processor scheduler
    • Scheduling algorithms
    • Scheduling criteria
    • Priorities
    • Scheduling policies
      • In Linux
  • Interprocess communication
    • Concepts
    • Philosopher dinner
    • Access primitives
      • Software solutions
      • Hardware solutions
    • Semaphores
    • Monitors
    • Message-passing
    • Unix IPC primitives
  • Deadlock
    • Introduction
    • Philosopher dinner - Solution 1
      • Deadlock prevention
    • Philosopher dinner - Solution 2
      • Deadlock prevention
    • Philosopher dinner - Solution 3
      • Deadlock prevention
    • Philosopher dinner - Solution 4
    • Deadlock avoidance
    • Deadlock detection
  • Memory management
    • Introduction
    • Address space
    • Contiguous memory allocation
    • Memory partitioning
    • Virtual memory system
    • Paging
    • Segmentation
    • Combining segmentation and paging
    • Page replacement
      • Policies
    • Working set
    • Thrashing
    • Demand paging vs. preparing
Powered by GitBook
On this page
  • Solution 1
  • State Diagram
  • Code
  • Deadlock conditions
  1. Deadlock

Philosopher dinner - Solution 1

PreviousIntroductionNextDeadlock prevention

Last updated 2 years ago

Solution 1

State Diagram

This is a possible solution for the dining-philosopher problem.

  • when a philosopher gets hungry, he/she first gets the left fork and then holds it while waits for the right one.

Let’s look at the implementation of this solution!

Code

Deadlock conditions

This solution works some times, but can suffer from deadlock.

Let’s identify the four necessary conditions.

  • mutual exclusion – the forks are not sharable at the same time.

  • hold and wait – each philosopher, while waiting to acquire the right fork, holds the left one.

  • no preemption – only the philosophers can release the fork(s) in their possession.

  • circular wait – if all philosophers acquire the left fork, there is a chain in which every philosopher waits for a fork in possession of another philosopher.