1 / 6

SHUBHAM CHAUHAN

SHUBHAM CHAUHAN. DEADLOCKS AND STARVATION THE READERS-WRITERS PROBLEM. 11CS10022. DEADLOCKS AND STARVATION. Deadlock : Two or more processes waiting indefinitely for an event that can be caused only by one of the waiting processes.

cleo
Télécharger la présentation

SHUBHAM CHAUHAN

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SHUBHAM CHAUHAN DEADLOCKS AND STARVATION THE READERS-WRITERS PROBLEM 11CS10022

  2. DEADLOCKS AND STARVATION • Deadlock: Two or more processes waiting indefinitely for an event that can be caused only by one of the waiting processes. • To illustrate this, consider a system consisting of two processes, P0 and P1, each accessing two semaphores, S and Q, set to the value 1: P0 P1 Wait(S); Wait(Q); Wait(Q); Wait(S); .. .. .. .. Signal(S); Signal(Q); Signal(Q); Signal(S); 1

  3. DEADLOCKS AND STARVATION • Now suppose P0 executes Wait(S) and then P1 executes Wait(Q). When P0 executes Wait(Q), it must wait until P1 executes signal(Q). Similarly, when P1 executes Wait(S), it must wait until P0 executes Signal(S). Since these Signal() operations cannot be executed, P0 and P1 are deadlocked. • Another problem related to deadlocks is indefinite blocking, or starvation, a situation in which processes wait indefinitely within the semaphore. Indefinite blocking may occur if we add and remove processes from the list associated with a semaphore with a semaphore in LIFO (last-in-first-out) order. 2

  4. THE READERS-WRITERS PROBLEM • A data set is shared among a number of concurrent processes • Readers – only read; they do not perform any updates • Writers – can both read and write • Problem: • Allow multiple readers to read at the same time. • Only one writer can access the shared data at the same time. • Shared Data • Data set • Semaphore mutex initialized to 1 • Semaphore wrt initialized to 1 • Integer readcount initialized to 0 3

  5. THE READERS-WRITERS PROBLEM • Writer: do { wait (wrt) ; … //writing is performed … signal (wrt) ; } while (TRUE); • Reader: do { wait (mutex) ; readcount++ ; if (readcount == 1) wait (wrt) ; signal (mutex) // reading is performed wait (mutex) ; readcount- - ; if (readcount == 0) signal (wrt) ; signal (mutex) ; } while (TRUE); 4

  6. THE READERS-WRITERS PROBLEM • Note that , if a writer is in the critical section and n readers are waiting, then one reader is queued on wrt, and n-1 readers are queued on mutex. Also observe that, when a writer executes Signal(wrt), we may resume the execution of either the waiting readers or a single waiting writer. The selection is made by the scheduler. • The readers-writers problem and its solution has been generalized to provide reader-writer locks on some systems. • Reader-writer locks are most useful in the following situations: • In applications where it is easy to identify which processes only read shared data and which threads only write shared data. • In applications that have more readers than writers. This is because reader-writer locks generally require more overhead to establish than semaphores or mutual exclusion locks, and the overhead for setting up a reader - writer lock is compensated by the increased concurrency of allowing multiple readers. 5

More Related