Lecture 4
           Interprocess and Scheduling

                 4.1. Interprocess communication
                 4.2. C...
Interprocess Communication
                   Race Conditions




Two processes want to access shared memory at same time
...
Critical Regions (1)

Four conditions to provide mutual exclusion
1.   No two processes simultaneously in critical region
...
Critical Regions (2)




        Mutual exclusion using critical regions
Sistem Operasi       http://fasilkom.narotama.ac....
Mutual Exclusion with Busy Waiting (1)




  Proposed solution to critical region problem
     (a) Process 0.
Sistem Opera...
Mutual Exclusion with Busy Waiting (2)




  Sistem Operasi   http://fasilkom.narotama.ac.id/
Peterson's solution for achi...
Mutual Exclusion with Busy Waiting (3)




Entering and leaving a critical region using the
Sistem Operasi TSL instruction...
Sleep and Wakeup




Producer-consumer http://fasilkom.narotama.ac.id/ fatal race condition8
   Sistem Operasi
           ...
Semaphores




TheSistem Operasi http://fasilkom.narotama.ac.id/
    producer-consumer problem using semaphores      9
Mutexes




Implementation of mutex_lock and mutex_unlock
 Sistem Operasi   http://fasilkom.narotama.ac.id/
              ...
Monitors (1)




Sistem Operasi   Example of a monitor
                    http://fasilkom.narotama.ac.id/
               ...
Monitors (2)




• Outline of producer-consumer problem with monitors
  – only one monitor procedure active at one time
  ...
Monitors (3)




Solution to producer-consumer problem in Java (part 1)
 Sistem Operasi    http://fasilkom.narotama.ac.id/...
Monitors (4)




Solution to producer-consumer problem in Java (part 2)
Sistem Operasi    http://fasilkom.narotama.ac.id/
...
Message Passing




The producer-consumer problem with N messages
 Sistem Operasi  http://fasilkom.narotama.ac.id/
       ...
Barriers




• Use of a barrier
      – processes approaching a barrier
      – all processes but one blocked at barrier
S...
Dining Philosophers (1)


•   Philosophers eat/think
•   Eating needs 2 forks
•   Pick one fork at a time
•   How to preve...
Dining Philosophers (2)




A nonsolution to the dining philosophers problem
 Sistem Operasi         http://fasilkom.narot...
Dining Philosophers (3)




Sistem Operasi         http://fasilkom.narotama.ac.id/
Solution to dining philosophers problem...
Dining Philosophers (4)




Sistem Operasi      http://fasilkom.narotama.ac.id/
Solution to dining philosophers problem (p...
The Readers and Writers Problem




 A solution to the readers and writers problem
Sistem Operasi   http://fasilkom.narota...
The Sleeping Barber Problem (1)




Sistem Operasi   http://fasilkom.narotama.ac.id/
                                     ...
The Sleeping Barber Problem (2)




Sistem Operasi    http://fasilkom.narotama.ac.id/
                 Solution to sleepin...
Scheduling
                   Introduction to Scheduling (1)




• Bursts of CPU usage alternate with periods of I/O wait
...
Introduction to Scheduling (2)




Sistem Operasi   Scheduling Algorithm Goals
                        http://fasilkom.nar...
Scheduling in Batch Systems (1)




   An example of shortest job first scheduling
Sistem Operasi   http://fasilkom.narota...
Scheduling in Batch Systems (2)




Sistem Operasi   Three level scheduling
                     http://fasilkom.narotama....
Scheduling in Interactive Systems (1)




• Round Robin Scheduling
  – list of runnable processes
  – list of runnable pro...
Scheduling in Interactive Systems (2)




A scheduling algorithm with four priority classes
 Sistem Operasi   http://fasil...
Scheduling in Real-Time Systems


Schedulable real-time system
• Given
     – m periodic events
     – event i occurs with...
Policy versus Mechanism

• Separate what is allowed to be done with
  how it is done
      – a process knows which of its ...
Thread Scheduling (1)




      Possible scheduling of user-level threads
        • 50-msec process quantum
        • thre...
Thread Scheduling (2)




      Possible scheduling of kernel-level threads
        • 50-msec process quantum
        • th...
Question ?




Sistem Operasi   http://fasilkom.narotama.ac.id/
                                                   34
Upcoming SlideShare
Loading in …5
×

Kcd226 Sistem Operasi Lecture04

616 views

Published on

Published in: Education, Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
616
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Kcd226 Sistem Operasi Lecture04

  1. 1. Lecture 4 Interprocess and Scheduling 4.1. Interprocess communication 4.2. Classical IPC problems 4.3. Scheduling Sistem Operasi http://fasilkom.narotama.ac.id/ 1
  2. 2. Interprocess Communication Race Conditions Two processes want to access shared memory at same time Sistem Operasi http://fasilkom.narotama.ac.id/ 2
  3. 3. Critical Regions (1) Four conditions to provide mutual exclusion 1. No two processes simultaneously in critical region 2. No assumptions made about speeds or numbers of CPUs 3. No process running outside its critical region may block another process 4. No process must wait forever to enter its critical region Sistem Operasi http://fasilkom.narotama.ac.id/ 3
  4. 4. Critical Regions (2) Mutual exclusion using critical regions Sistem Operasi http://fasilkom.narotama.ac.id/ 4
  5. 5. Mutual Exclusion with Busy Waiting (1) Proposed solution to critical region problem (a) Process 0. Sistem Operasi (b) Process 1. http://fasilkom.narotama.ac.id/ 5
  6. 6. Mutual Exclusion with Busy Waiting (2) Sistem Operasi http://fasilkom.narotama.ac.id/ Peterson's solution for achieving mutual exclusion 6
  7. 7. Mutual Exclusion with Busy Waiting (3) Entering and leaving a critical region using the Sistem Operasi TSL instruction http://fasilkom.narotama.ac.id/ 7
  8. 8. Sleep and Wakeup Producer-consumer http://fasilkom.narotama.ac.id/ fatal race condition8 Sistem Operasi problem with
  9. 9. Semaphores TheSistem Operasi http://fasilkom.narotama.ac.id/ producer-consumer problem using semaphores 9
  10. 10. Mutexes Implementation of mutex_lock and mutex_unlock Sistem Operasi http://fasilkom.narotama.ac.id/ 10
  11. 11. Monitors (1) Sistem Operasi Example of a monitor http://fasilkom.narotama.ac.id/ 11
  12. 12. Monitors (2) • Outline of producer-consumer problem with monitors – only one monitor procedure active at one time Sistem Operasi http://fasilkom.narotama.ac.id/ – buffer has N slots 12
  13. 13. Monitors (3) Solution to producer-consumer problem in Java (part 1) Sistem Operasi http://fasilkom.narotama.ac.id/ 13
  14. 14. Monitors (4) Solution to producer-consumer problem in Java (part 2) Sistem Operasi http://fasilkom.narotama.ac.id/ 14
  15. 15. Message Passing The producer-consumer problem with N messages Sistem Operasi http://fasilkom.narotama.ac.id/ 15
  16. 16. Barriers • Use of a barrier – processes approaching a barrier – all processes but one blocked at barrier Sistem Operasi http://fasilkom.narotama.ac.id/ – last process arrives, all are let through 16
  17. 17. Dining Philosophers (1) • Philosophers eat/think • Eating needs 2 forks • Pick one fork at a time • How to prevent deadlock Sistem Operasi http://fasilkom.narotama.ac.id/ 17
  18. 18. Dining Philosophers (2) A nonsolution to the dining philosophers problem Sistem Operasi http://fasilkom.narotama.ac.id/ 18
  19. 19. Dining Philosophers (3) Sistem Operasi http://fasilkom.narotama.ac.id/ Solution to dining philosophers problem (part 1) 19
  20. 20. Dining Philosophers (4) Sistem Operasi http://fasilkom.narotama.ac.id/ Solution to dining philosophers problem (part 2) 20
  21. 21. The Readers and Writers Problem A solution to the readers and writers problem Sistem Operasi http://fasilkom.narotama.ac.id/ 21
  22. 22. The Sleeping Barber Problem (1) Sistem Operasi http://fasilkom.narotama.ac.id/ 22
  23. 23. The Sleeping Barber Problem (2) Sistem Operasi http://fasilkom.narotama.ac.id/ Solution to sleeping barber problem. 23
  24. 24. Scheduling Introduction to Scheduling (1) • Bursts of CPU usage alternate with periods of I/O wait – a CPU-bound process – an I/O bound process Sistem Operasi http://fasilkom.narotama.ac.id/ 24
  25. 25. Introduction to Scheduling (2) Sistem Operasi Scheduling Algorithm Goals http://fasilkom.narotama.ac.id/ 25
  26. 26. Scheduling in Batch Systems (1) An example of shortest job first scheduling Sistem Operasi http://fasilkom.narotama.ac.id/ 26
  27. 27. Scheduling in Batch Systems (2) Sistem Operasi Three level scheduling http://fasilkom.narotama.ac.id/ 27
  28. 28. Scheduling in Interactive Systems (1) • Round Robin Scheduling – list of runnable processes – list of runnable processes after B uses up its quantum Sistem Operasi http://fasilkom.narotama.ac.id/ 28
  29. 29. Scheduling in Interactive Systems (2) A scheduling algorithm with four priority classes Sistem Operasi http://fasilkom.narotama.ac.id/ 29
  30. 30. Scheduling in Real-Time Systems Schedulable real-time system • Given – m periodic events – event i occurs within period Pi and requires Ci seconds • Then the load can only be handled if m Ci ∑ P ≤1 i =1 Sistem Operasi i http://fasilkom.narotama.ac.id/ 30
  31. 31. Policy versus Mechanism • Separate what is allowed to be done with how it is done – a process knows which of its children threads are important and need priority • Scheduling algorithm parameterized – mechanism in the kernel • Parameters filled in by user processes – policy set by user process Sistem Operasi http://fasilkom.narotama.ac.id/ 31
  32. 32. Thread Scheduling (1) Possible scheduling of user-level threads • 50-msec process quantum • threads run http://fasilkom.narotama.ac.id/ Sistem Operasi 5 msec/CPU burst 32
  33. 33. Thread Scheduling (2) Possible scheduling of kernel-level threads • 50-msec process quantum • threads run http://fasilkom.narotama.ac.id/ Sistem Operasi 5 msec/CPU burst 33
  34. 34. Question ? Sistem Operasi http://fasilkom.narotama.ac.id/ 34

×