graph LR
SP(同步原语 Sync Primitives) ---> std::mutex
SP ---> std::condition_variable
SP ---> std::counting_semaphore
SP ---> std::barrier
SP ---> std::latch
mutex
condition_variable
semaphore
counting_semaphore
 | 
 | 
| 计数器值范围 | acquire() 行为 | 
          release() 行为 | 
      
|---|---|---|
计数器 = 0 | 
          阻塞直到新的 release(),计数器不变=0  | 
          立即成功, 计数器+1  | 
      
0 < 计数器 < max | 
          立即成功, 计数器-1  | 
          立即成功, 计数器+1  | 
      
计数器 = max | 
          立即成功, 计数器-1  | 
          计数器不变=max, 超出的增量会导致未定义行为  | 
      
binary_semaphore
相当于 std::counting_semaphore<1>
latch
 | 
 | 
barrier
 | 
 | 
C++20 同步原语总结
    
      barrier $\subseteq$ latch $\subseteq$ semaphore