• Coordination of execution of multiple Process (进程) or Thread in a system to ensure that they access shared resources in a controlled and predictable manner
  • The table below lists some common synchronisation methods
Synchronization MethodUsageAdvantagesDisadvantagesExample Use Case
Barrier (屏障)Synchronise threads at a pointSimple, ensures synchronisationLimited use casesParallel computing phases
Condition Variable (条件变量)Wait for condition with mutexHandles complex conditionsComplex, potential Race Condition (竞态条件)Producer-consumer problems
Mutex (互斥体)Protect shared dataSimple, effectiveContention, potential Deadlock (死锁)Critical sections
Semaphore (信号量)Control access to resourcesFlexible, versatileComplex, potential errorsResource pools
SpinlockBusy Waiting for short periodsLow overhead for short waitsInefficient for long waitsLow-level programming