377 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.
lock, Monitor, Mutex, Semaphore, SemaphoreSlim, SpinLock, ReaderWriterLockSlim, Interlocked, Volatile and memory barriers.
lock lowering to Monitor or Lock.EnterScope, choosing the lock object, re-entrancy, why you cannot await inside a lock, and lock scope design.
Monitor.Enter/Exit, TryEnter with timeouts, Wait/Pulse/PulseAll condition signalling, thread affinity and the object header thin lock and sync block.
Kernel mutex, cross-process named mutexes, Global and Local prefixes, AbandonedMutexException, thread affinity, cost and single-instance apps.
Counting semaphores, System.Threading.Semaphore as a kernel object, named semaphores and platform limits, no thread affinity, SemaphoreFullException and use cases.
SemaphoreSlim internals, WaitAsync with timeouts and cancellation, async mutual exclusion, throttling HTTP calls, non-reentrancy and release discipline.
SpinLock and SpinWait, busy-waiting versus blocking, struct copying pitfalls, owner tracking and why most code should not use it.
Read, write and upgradeable read locks, recursion policy, thread affinity, performance reality and lock-free alternatives for read-mostly data.
Atomic Increment, Add, Exchange, CompareExchange, Read, And and Or; full fences; CAS loops; ABA and when lock-free is worth it.
Compiler and CPU reordering, acquire and release semantics, the volatile keyword, Volatile class, x64 versus Arm64 memory models and what volatile does not guarantee.
Store buffers and reordering, full versus half fences, Interlocked.MemoryBarrier, implicit barriers in locks and Interlocked, double-checked locking and MemoryBarrierProcessWide.