进程、线程同步互斥学习 —— 互斥器

本文介绍了C++中的互斥器Mutex,它用于实现线程间的同步互斥。Mutex在未被任何线程占用时为有信号状态,被占用时则变为无信号状态。创建Mutex可以通过CreateMutex或CreateMutexEx函数,并可指定是否立即拥有和命名。持有Mutex的线程可以使用ReleaseMutex释放。等待Mutex所有权可使用wait函数如WaitForSingleObject等。
摘要由CSDN通过智能技术生成

关于互斥器,先看MSDN介绍:

Mutex Objects
A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned. Only one thread at a time can own a mutex object, whose name comes from the fact that it is useful in coordinating mutually exclusive access to a shared resource. 

即:Mutex可以被某一个线程在某一时刻被单独拥有,Mutex从有信号转变成无信号。


初始化

A thread uses the CreateMutex orCreateMutexEx function to create a mutex object. The creating thread can request immediate ownership of the mutex object and can also specify a name for the mutex object. It can also create an unnamed mutex. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值