Overview

Object –> CriticalFinalizerObject –> Thread

Synchronizing Access to Shared Resources

Monitor

Synchronize access to objects.

  • The Monitor class allows you to synchronize access to a region of code by taking and releasing a lock on a particular object by calling the Monitor.Enter, Monitor.TryEnter, and Monitor.Exit methods.
  • You can also use the Monitor class to ensure that no other thread is allowed to access a section of application code being executed by the lock owner, unless the other thread is executing the code using a different locked object.
  • Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.threading.monitor?view=net-6.0

Semaphore

Use the Semaphore class to control access to a pool of resources.

Mutex

A synchronization primitive that can also be used for inter-process synchronization.

Interlocked

Provides atomic operations for variables that are shared by multiple threads.