當(dāng)前位置:首頁 > IT技術(shù) > Windows編程 > 正文

Linux和windows臨界區(qū)
2021-09-28 16:47:40

1.聲明

?

#ifdef _LINUX

pthread_mutex_t ? mutex_lock;

#endif

#ifdef WIN32

CRITICAL_SECTION ?mutex_lock;

#endif

2.初始化

?

#ifdef _LINUX

pthread_mutex_init(&mutex_lock, NULL);

#endif

#ifdef WIN32

InitializeCriticalSection(&mutex_lock);

#endif

3.進(jìn)入和退出臨界區(qū)

?

#ifdef _LINUX

thread_mutex_lock(&mutex_lock);

......

pthread_mutex_unlock(&mutex_lock);

#endif

?

#ifdef _WIN32

EnterCriticalSection(&mutex_lock);

....

LeaveCriticalSection(&mutex_lock);

#endif


4.刪除臨界區(qū)


#ifdef _LINUX


pthread_mutex_destroy(&mutex_lock);


#endif


#ifdef WIN32


DeleteCriticalSection(&mutex_lock);


#endif


版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。


本文摘自 :https://blog.51cto.com/l

開通會(huì)員,享受整站包年服務(wù)立即開通 >