1 The Interlocked Family of Functions
LONG InterlockedExchangeAdd( PLONG plAddend, LONG lIncrement ); ....
2 volatile
3 Critical Sections
CRITICAL_SECTION
VOID InitializeCriticalSection(PCRITICAL_SECTION pcs);
BOOL InitializeCriticalSectionAndSpinCount(PCRITICAL_SECTION pcs, DWORD dwSpinCount);DWORD SetCriticalSectionSpinCount(PCRITICAL_SECTION pcs, DWORD dwSpinCount);
If you call this function while running on a single processor machine,
the dwSpinCount parameter is ignored and the count is always set to 0.
This is good because setting a spin count on a single-processor machine
is useless: the thread owning the resource can't relinquish it if another
thread is spinning.......
本文介绍了Windows环境下实现线程同步的两种方法:Interlocked系列函数和临界区(CriticalSection)。Interlocked函数用于进行原子操作,而临界区则通过加锁解锁机制保护共享资源。文中还详细讨论了临界区的初始化及设置自旋计数。
922

被折叠的 条评论
为什么被折叠?



