标签:
一.Mutual exclusion
A mutex object facilitates protection against data races and allows safe synchronization of data between execution agents (30.2.5).
互斥对象有助于防止数据竞争,允许在执行的数据之间安全同步,,允许安全的同步执行中的数据
#include <thread> #include <mutex> using namespace std; std::thread SB(&SUSAKE::Test, this); SB.detach(); void Susake::Test() { while(1) { mutex.lock(); if(t > 0) { printf("%d", t--); mutex.unlock(); } else { mutex.unlock(); break; } } }
二.Condition variables
Condition variables provide synchronization primitives used to block a thread until notified by some other thread that some condition is met or until a system time is reached.
标签:
原文地址:http://www.cnblogs.com/Susake/p/4711529.html