Windows Thread Synchronization With Kernel Objects

<script type="text/javascript"> google_ad_client="pub-6065469188450680"; google_ad_width=728; google_ad_height=90; google_ad_format="728x90_as"; google_ad_type="text_image"; google_ad_channel="6872543818"; </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

The following kernel objects can be in a signaled or nonsignaled state:

    Processes    Threads    Jobs    Files    Console input    File change notifications

    Events    Waitable timers    Semaphores    Mutexes       

The rules for a semaphore are as follows:

    If the current resource count is greater than 0, the semaphore is signaled.

    If the current resource count is 0, the semaphore is nonsignaled.

    The system never allows the current resource count to be negative.

    The current resource count can never be greater than the maximum resource count.

 

Mutex objects are different from all other kernel objects because they have a notion of "thread ownership."

Characteristic                                 Mutex                                         Critical Section
Performance                                    Slow                                          Fast
Can be used across process boundaries          Yes                                           No
Declaration                                    HANDLE hmtx;                                  CRITICAL_SECTION cs;
Initialization                                 hmtx= CreateMutex(NULL, FALSE, NULL);         InitializeCriticalSection(&cs);
Cleanup                                        CloseHandle(hmtx);                            DeleteCriticalSection(&cs);
Infinite wait                                  WaitForSingleObject(hmtx, INFINITE);          EnterCriticalSection(&cs);
0 wait                                         WaitForSingleObject(hmtx, 0);                 TryEnterCriticalSection(&cs);
Arbitrary wait                                 WaitForSingleObject(hmtx, dwMilliseconds);    Not possible
Release                                        ReleaseMutex(hmtx);                           LeaveCriticalSection(&cs);
Can be waited on with other kernel objects     Yes                                           No

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值