Presentation is loading. Please wait.

Presentation is loading. Please wait.

CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11:30 - 12:30 AM.

Similar presentations


Presentation on theme: "CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11:30 - 12:30 AM."— Presentation transcript:

1 CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11:30 - 12:30 AM

2 Last time:  CPU Scheduling  Process synchronization Today Process synchronization  Transactions  Locks  Deadlocks  Semaphores  Monitors  Thread coordination with a bounded buffer. Next time  Process synchronization Reading assignments  Chapter 6 of the textbook Lecture 26 – Wednesday, March 20, 2013 Lecture 262

3 Transaction Transaction processing  information processing that is divided into individual, indivisible operations. Transaction  operation that must succeed or fail as a complete unit; it cannot remain in an intermediate state. Example - ordering an airline ticket requires two actions: payment, and a seat reservation. The user must either:  both pay for and reserve a seat; OR  neither pay for nor reserve a seat. In database systems, atomicity (from Greek a-tomos, undividable) is one of the ACID transaction properties. ACID – atomicity – consistency – isolation- durability  Atomicity  indivisibility of an operation.  Consistency  a transaction will bring the database from one valid state to another.  Isolation  concurrent execution of transactions results in a system state that would be obtained if transactions were executed one after another.  Durability  a transaction has been committed, it will remain so. Lecture 26 3

4 Why do we need concurrency control? In a transaction processing system we have to guarantee the ACID properties. Example: An electronic funds transfer requires several steps: 1. Get the current balance 2. Check that the transaction is possible - if enough funds are available in case of a withdraw. 3. Compute the new balance. 4. Write the new balance. 5. Complete the transaction – transfer the funds. The system may fail at any point and we have to guarantee that either all steps are completed or none. What if two transactions act upon an account, e.g., there arte two threads T1 and T2 which both wish to withdraw from the account? Lecture 264

5 Critical concepts for thread coordination Critical section  code that accesses a shared resource. Race conditions  two or more threads access shared data and the result depends on the order in which the threads access the shared data. Mutual exclusion  only one thread should execute a critical section at any one time. Lock  shared variable which acts as a flag to coordinate access to shared data. Spin lock  A spin lock causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available. It is also called a ``busy waiting'' as the processor is busy checking the lock. Thus, on a single processor/single core system no other thread can run and the one holding the lock cannot release it Side effects of thread coordination  Deadlock  Priority inversion  a lower priority activity is allowed to run before one with a higher priority Lecture 265

6 6

7 Deadlocks Happen quite often in real life and the proposed solutions are not always logical: “When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone.” a pearl from Kansas legislation. Deadlock jury. Deadlock legislative body. Lecture 267

8 Examples of deadlock Traffic only in one direction. Solution  one car backs up (preempt resources and rollback). Several cars may have to be backed up. Starvation is possible. Lecture 268

9 9

10 Thread deadlock Deadlocks  prevent sets of concurrent threads/processes from completing their tasks. How does a deadlock occur  a set of blocked threads each holding a resource and waiting to acquire a resource held by another thread in the set. Example  locks A and B, initialized to 1 P 0 P 1 wait (A);wait(B) wait (B);wait(A) Aim  prevent or avoid deadlocks Lecture 2610

11 Lecture 2611


Download ppt "CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11:30 - 12:30 AM."

Similar presentations


Ads by Google