码迷,mamicode.com
首页 > 其他好文 > 详细

【Thread support library】

时间:2015-08-07 19:20:47      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

一.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. 

 



【Thread support library】

标签:

原文地址:http://www.cnblogs.com/Susake/p/4711529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!