??Windows????????С?????????μ???????
???????????? ???????[ 2012/10/17 10:55:12 ] ????????
???????ù???????????????CRITICAL_SECTION?????????κ???????????????EnterCriticalSection??LeaveCriticalSection???
??????
Int g_a=0;
CRITICAL_SECTION cs;
DWORD WINAPI ThreadProc1(PVOID)
{
EnterCriticalSection(&g_a);
for(int i=0;i<100;i++)
g_a++;
LeaveCriticalSection(&cs);
return 0;
}
DWORD WINAPI ThreadProc2(PVOID)
{
EnterCriticalSection(&g_a);
for(int i=0;i<100;i++)
g_a++;
LeaveCriticalSection(&cs);
return 0;
}
?????????????????????????????CRITICAL_SECTION?????????????????????????????????????????????????????????????????????????ж???????????????????????CRITICAL_SECTION????????EnterCriticalSection????CRITICAL_SECTION????????????????????????????????????????????????????????????????????????????????????????????????????á???????????????EnterCriticalSection?????????????????????????????????????????????????????????????????????????ù???????????????????????δ???????LeaveCriticalSection????????????????????????????????????LeaveCriticalSection????????????????????????????????????
???????????????????????Interlock??к???????????????????????????????????????????????????????????????????
????????????CRITICAL_SECTION??????????????????????????????????????????????????????????Щ???????????н????????????????????з?????????????г????????????
?????????????????????
?????? ?????????????????????????????????????CRITICAL_SECTION????????
????????????κ??????????????????????????CRITICAL_SECTION?????г????????????????
VOID InitializeCriticalSection(PCRITICAL_SECTION pcs);
???????????????CRITICAL_SECTION?????Щ??????????Щ?????о?????????????????????????
???????????????????????????????????o?????????CRITICAL_SECTION????
<SPAN style="FONT-SIZE: 18px">VOID DeleteCriticalSection(PCRITICAL_SECTION pcs);</SPAN>
???????????????????EnterCriticalSection???ú??????????????????
????1??????????????????????ú???????3?????????????????????????????????????μ??????????????????????????????С?
????2???????????????????????ú????????????????????????????л?????????????????????LeaveCriticalSection??????????????CRITICAL_SECTION?????????????????????л????????????
????????????????????????????????????????????????TryEnterCriticalSection???????ú??????????????????????????????????????????????ú???????false????????true??
??????????????????????????????????????????????飬???????????????TryEnterCriticalSection?????????CRITICAL_SECTION?????Щ?????????????????LeaveCriticalSection??????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11