宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

handle createmutex LP security _ attributeslpmutexattributes,//指向安全属性的指针BOOL bInitialOwner,//独占对象的所有者lpctstr LP

1. CreateMutex只是做了一把钥匙,这把钥匙由你自己决定是用来锁门,锁抽屉,还是锁你对象的内衣。

2.lpName是指定此密钥的名称。 你可以不用给这把钥匙取名字。 但是,如果有同样的名字,在跨过程锁门时,就可以得到同样的钥匙。

3.handlem _ hmutex=createmutex null,TRUE,’ cplusplus_me ‘ ); 只是做了锁,到现在这个句子完成了,他什么也没锁门。

//进行锁定

witforsingleobjecthmutex,INFINITE ); 如MSDN所述,也可以使用其他函数

//在这里写锁定的东西。 一般操作共享数据消耗系统内存)。

//解除锁定

releasemutexhmutex;

/*编写锁定的类,有效安全地控制共享的数据,并显示内存错误*/classmtcmutex { public : MTC mutex 3360 _ mutex null ) this-_mutex 空) this ) this-_mutex=NULL; }MTCmutexconstMTCmutexmutex ) { *this=mutex; } mtcmutexoperator=constmtcmutexother ) ifthis!=other this-_ mutex=other._ mutex; }返回* this; }private:HANDLE _mutex; 公共: void lock waitforsingleobject ) this-_mutex,INFINITE ); }void UnLock ) Releasemutex ) this-_mutex ); };