Operating Systems COMP 4850CISG 5550 - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Operating Systems COMP 4850CISG 5550

Description:

... the value of the ... the producer and consumer do not access the buffer at the same time ... Semaphores that are set to 1, and used by 2 processes to ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 19
Provided by: nccu
Category:

less

Transcript and Presenter's Notes

Title: Operating Systems COMP 4850CISG 5550


1
Operating SystemsCOMP 4850/CISG 5550
  • Interprocess Communication, Part II
  • Dr. James Money

2
Semaphores
  • In 1965, Dijkstra introduced the idea of a
    semaphore for the producer-consumer problem.
  • A semaphore is an integer variable to count the
    number of wakeups.
  • The semaphore is 0 if there are no wakeups saved,
    or some positive value is there are some waiting.

3
Semaphores
  • There are two operations on the semaphore
  • up
  • down
  • These generalize sleep and wakeup

4
Semaphore - down
  • The down function does the following
  • If the value of the semaphore is greater than 0,
    it decrements the value
  • If the value is 0, the process it put to sleep
    without completing down
  • This is done as an atomic operation

5
Semaphore up
  • The up function does the following
  • Increments the value of the semaphore
  • If one of the processes running down are
    sleeping, it is chosen by the system to complete
    its down operation. In this case, the semaphore
    remains 0.

6
Solving P-C Problem with Semaphores
  • We can solve the producer-consumer problem with
    semaphores
  • We need three semaphores
  • full counting the number of slots full
  • empty counting the slots that are empty
  • mutex to ensure the producer and consumer do
    not access the buffer at the same time

7
P-C Problem with Semaphores
  • Initially
  • full 0
  • emptyN
  • mutex 1
  • Semaphores that are set to 1, and used by 2
    processes to ensure only one of them enter their
    critical region at a time are called binary
    semaphores.

8
P-C Problem with Semaphores
9
Mutexes
  • When the counting ability of a semaphore is not
    needed, we use a binary version called a mutex.
  • A mutex is a variable that can be in one of two
    states
  • locked
  • unlocked

10
Mutexes
  • There are two functions
  • mutex_lock
  • mutex_unlock

11
mutex_lock
  • If the mutex is unlocked, the mutex is locked and
    the program can enter its critical regions
  • If the mutex is locked, the calling thread is
    blocked until mutex_unlock has been called by
    another thread
  • If multiple threads are blocked mutex_lock, then
    one of them is chosen to be given the lock.

12
mutex_unlock
  • mutex_unlock setp the mutex to 0, and unblocks a
    process if needed

13
Mutexes
Mutexes are simple enough to implement in user
space
14
Message Passing
  • When multiple machines are involved, none of the
    prior solutions work.
  • This new IPC method is called message passing.
  • There are two functions
  • send(destination, message)
  • receive(source,message)

15
Message Passing
  • Design Issues
  • Messages can be lost there must be some
    acknowledgement of the received message
  • What if a message is received twice? Use sequence
    numbers or message tags
  • How to name processes and ensure authentication?

16
P-C Problem with Message Passing
17
Barriers
  • Barriers are used when one process may not
    proceed until another process reaches a certain
    point
  • When a process reaches a barrier call, it blocks
    until all the processes call barrier

18
Barriers
Write a Comment
User Comments (0)
About PowerShow.com