CS318 Project #3Continuing from Project 2Multi-ThreadingWhat do you have to do?LockLock (cont.)Condition VariablesSemaphoreMutexBarrierHandling InterruptsSlide 12The End1CS318 Project #3Preemptive Kernel2Continuing from Project 2Project 2 involved:Context SwitchStack ManipulationSaving StateMoving between threads, but in a non-preemptive environment3Multi-ThreadingNow you have to deal with the possibility of your context switch being interruptedTimer Interrupt (10 ms)Page Fault (later)TLB Miss (later)4What do you have to do?Implement locking primitives (thread.c)LockAcquire & ReleaseConditionSignal, Wait, BroadcastSemaphoreUp & DownBarrierWaitTimer Interrupt (entry.S)Also handle irq7 - call fake_irq7 instead of scheduler_entry5LockAcquiring and releasing a lock must be done atomicallyOtherwise …Release LockThread 1Thread 2Acquire LockCritical Section Critical SectionRelease LockAcquire Lock6Lock (cont.)Acquiring and Releasing of the lock should be done in a single threaded contextHow do you do this?Turn interrupts off for as small a window as possible7Condition VariablesWait operation cause the current thread to block on put itself of a wait listSignal causes a random thread on the wait list to start runningBroadcast wakes up all waiting threadsCondition Variables can “lose” signals if no thread is on the wait list to receive it8SemaphoreUse when you need a way to store wakeup signalsProducer-Consumer ProblemTwo operationsUp -> Called to wakeup a thread, if no thread is ready to be woken up, the wakeup signal is storedDown -> Called to see if a wakeup signal is stored, otherwise sleep9MutexA semaphore used for mutual exclusionSemaphore should only ever have values 0 and 1Useful when only one thread should execute a piece of code at a time10BarrierUsed to synchronize multiple threads at a single pointUsually the boundary between passes of phases of an algorithmCount number of threads stoppedCount number of threads started11Handling InterruptsSetting up of interrupt vector table already done for you.You only need to implement irq0_entry, fake_irq7_entrysyscall_entry already provided.12Handling InterruptsFor all interruptsSave the current stateTell the Interrupt Controller to allow more interrupts (EOI)Process the interruptUse iret to return from interruptsCall scheduler to move to next process on timer interrupt13The
View Full Document