????????????????????????

Long a;
DWORD WINAPI ThreadFunc2(PVOID pvParam)
{
   InterlockedExchangeAdd(&a??1);
   Return 0;
}

??????????????????a???????????????????С????????a???????2???????????????????????1????????????InterlockedIncrement??????

??????ЩInterlock??к???????????????????????е?cpu?????????x86???????Interlock?????????????????????????????????????????cpu???????????????

?????????????????Interlock????????ι????????????????????????????????????????cpu????Щ??????????????????????????????е??

????Interlock??к???????????????????????cpu????????????????????????????????л???

?????????Щ???????????????????????????ɡ?

???????????????????б???????????????

LONG InterlockedExchange(
   PLONG volatile  plTarget??
   LONG lValue);
LONGLONG InterlockedExchange64(
   PLONGLONG volatile  plTarget??
   LONGLONG lValue);
PVOID InterlockedPointer(
   PVOID *volatile ppvTarget??
   PVOID pvValue);

????InterloackedExchange??InterlockedExchangePointer???????????????????????????????????滻????????????????

????????32λ??ó????????????????滻??32λ???????????64λ????ó???InterlockedExchangePointer???滻??64λ?????????????????64λ???

?????????????????????????????????????????InterlockedExchange??????????á?

Bool use=false;
Void func()
{
   While(InterlockedExchange(&use??true)==true)
     Sleep(0);
//........
InterlockedExchange(&use??false);
}

????While??????????У???use??????true???????????????true????????????false????????????δ????á???????????????С????????????true???????????????????????????????sleep????????????????