This website uses cookies and similar technologies to understand visitors' experiences. By continuing to use this website, you accept our use of cookies and similar technologies,Terms of Use, and Privacy Policy.

Oct 11 2009 - 05:30 PM
OS Class 7th Oct, 09
Did not attended the class so writing down notes from the lectures: Three properties for synchronization - Mutually exclusive - Forward progress (if no body else in critical section, one process can get into critical section) - Bounded writing problems with using disable interrupts and enabled interrupts for locking and unlocking - only 1 lock can be handled - this can only help for locking one cpu(no SMP support) - cannot be blocking - userspace security type issues Then what do we do for Symmetric Multiprocessor Unit. FOR SMP ---------- Two new hardware instructions to be added: 1) Compare and Swap (CS) 2) TS + Hardware = NEW Instruction - TEST AND SET (TS) tests if the value is set, if not then sets the value [ATOMIC] implement a lock lock(x) { while (TS(x)); //if not set then sets, if it's set then spins } unlock(x) { x = 0; } lock the bus for the CPU on a SMP. COMPARE AND SWAP(CS) IF (x != y) SWAP(x,y) use case scenario: lock(x) { key = 1; while (key) {CS(x,key);} // x happens to be zero then swap happens } unlock(x) { x = 0; } These are called spin locks where one gets spinning on the CPU, there are other types of lock which would require Reason for using Spin lock - Don't have to wait long it's ease - programming is easier - not a long time for contention. - then they redesigning the locking mechanism OS [SMP support for an OS build for uni processor] - lock (scheduler) - lock (memory) - lock (network) - lock (file system) pick your locks that the critical section is small as possible. Different types of lock - Spin Locks() - Semaphore (COUNTING, BINARY SEMAPHORE) (Locking) DOWN - P - Proberen(test) (Unlocking) UP - V - Verhogen(increment) COUNTING SEMAPHORE --------------- Allows more than n guys through P(s) { WHILE(s
|By: Pranav Garg|10933 Reads