Sobes.tech
Senior

What primitives of synchronization do you know in OS?

sobes.tech AI

Answer from AI

Synchronization primitives in operating systems are mechanisms that allow managing access to shared resources and coordinating the execution of threads or processes. The main primitives:

  • Mutexes (Mutex) — provide exclusive access to a resource, blocking it for other threads.
  • Semaphores (Semaphore) — limit the number of threads that can work with a resource simultaneously.
  • Spinlocks (Spinlock) — locks where the thread actively waits for the resource to be released, without sleeping.
  • Barrier (Barrier) — synchronizes a group of threads, making them wait for each other at a certain point.
  • Condition Variables (Condition Variables) — allow threads to wait for a certain condition to occur and notify each other.

In Go, for example, there are wrappers over these primitives in the sync package:

var mu sync.Mutex
mu.Lock()
// critical section
mu.Unlock()

These primitives help prevent data races and ensure correct operation of multithreaded programs.

What primitives of synchronization do you know in OS… - sobes.tech