self-confidence,the source of all the power

导航

C++多线程信号量,互斥

windows 编程,多线程

临界区:

  CRITICAL_SECTION cs; //相当于给该代码段加了一把锁,其它线程不可访问,直到当前线程释放资源
       InitializeCriticalSection(
&cs);
//线程1:
       EnterCriticalSection(&cs);
              do something...

       LeaveCriticalSection(
&cs);
//线程2:
       EnterCriticalSection(&cs);
              do something

       LeaveCriticalSection(
&cs);
//最后:
       DeleteCriticalSection(&cs);

posted on 2013-03-18 01:32  漩涡鸣人  阅读(387)  评论(0编辑  收藏  举报