Understanding Windows Multithreading 8 Thread Synchronization Primitives Overview

  • Slides: 10
Download presentation
Understanding Windows. Multithreading- 8 Thread Synchronization Primitives - Overview and Classification By Anand George

Understanding Windows. Multithreading- 8 Thread Synchronization Primitives - Overview and Classification By Anand George

Synchronization primitives • Normally called LOCKs • Many types. • • Based on performance.

Synchronization primitives • Normally called LOCKs • Many types. • • Based on performance. Scenario. Purpose. User mode kernel mode.

Most Important classification – Interrupts masked or not. • An SMP system in which

Most Important classification – Interrupts masked or not. • An SMP system in which interrupts are masked. • What if the thread which tries to get the lock is not getting the lock as the lock is in use? • Wait ? Not possible. • Only spinlocks can be used. • Scheduler is not active and so wait cannot be done. • Remember wait is just and illusion by scheduler. • And scheduler is nothing but a timer interrupt handler. • So if interrupts are masked scheduler wont be able to do the job. • In windows all happens at a level called DPC which is not much relevant to the discussion.

Interrupts are enabled. • Thread which are not able to acquire the lock can

Interrupts are enabled. • Thread which are not able to acquire the lock can wait. • • Mutex, Semaphore. Critical Sections. Eresource All most all implemented with the help of Dispatcher Objects in windows to implement the wait.

User mode – Always interrupts enabled. • Critical Sections native windows. • Java has

User mode – Always interrupts enabled. • Critical Sections native windows. • Java has it own locking primitives so do with C# etc or similar multi threading featured programming languages. • Irrespective of the language all locks uses Dispatcher objects to perform the “wait” in windows. • Slim reader writer is a fairly new from windows 7. • Mutex and semaphore can be used but expensive for user mode in windows.

Kernel mode – Interrupts Enabled. • Mutex • Eresource ( read writer ) •

Kernel mode – Interrupts Enabled. • Mutex • Eresource ( read writer ) • Semaphore • Fast/Guarded Mutex ( as name implies high performance ) • More but all uses dispatcher objects or are dispatcher objects.

Kernel mode – Interrupt disabled • Dispatcher of scheduler is off. • No one

Kernel mode – Interrupt disabled • Dispatcher of scheduler is off. • No one to wake thread up. • Wait cannot be done. • Dispatcher object cannot be used. • Spinlock is the only option. • Waiters spin in an infinite loop until it get the lock. • Very expensive but the only option. • In a single processor scenario most of the spinlock implementation uses interrupt disable. • Normally OS developers or kernel device driver developers worry (uses) about these kinda locks. • More later.

Summary • Types of locks. • Why spinlock is needed while interrupts are masked.

Summary • Types of locks. • Why spinlock is needed while interrupts are masked. • Different types of user mode and kernel mode locks with interrupts enabled. • Most of them we going to see in next presentations. • We have not discussed user mode scheduling, and some kinda locks like pushlock etc in windows. • Also we deferred discussion about IRQL and especially DPC level in windows to make things simple.

Summary Table Interrupt Enabled Interrupted disabled only Kernel User Kernel CS Mutex ( common

Summary Table Interrupt Enabled Interrupted disabled only Kernel User Kernel CS Mutex ( common ) Java locks Eresource C# Semaphore ( common) Or any such Spinlocks

Thank you.

Thank you.