线程同步

时间:2014-05-28 09:38:14   收藏:0   阅读:205

win32可以使用

InterlockedIncrement

InterlockedDecrement

来使同一时间只有一个线程在访问变量

 

 

bubuko.com,布布扣
 1 ULONG _stdcall CA::AddRef()
 2 {
 3     return InterlockedIncrement(&m_ref);
 4 }
 5 
 6 ULONG _stdcall CA::Release()
 7 {
 8     if (InterlockedDecrement(&m_ref) == 0)
 9     {
10         delete m_ref;]
11         return 0;
12     }  
13     return m_ref;
14 }    
bubuko.com,布布扣

 

线程同步,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!