wetwoo的小窝
wetwoo的小窝

导航

<2008年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
统计
  • 随笔 - 22
  • 文章 - 4
  • 评论 - 14
  • 引用 - 0

留言簿(1)

随笔档案

文章档案

相册

搜索

最新评论

阅读排行榜

评论排行榜

2008年10月24日

http://msdn.microsoft.com/msdnmag/issues/01/09/hood
发表于 2008-10-24 11:23 wetwoo的小窝 阅读(308) | 评论 (0)编辑 收藏

2008年10月23日

http://msdn2.microsoft.com/en-us/library/aa375193.aspx
发表于 2008-10-23 19:06 wetwoo的小窝 阅读(376) | 评论 (2)编辑 收藏

2008年10月22日

http://msdn.microsoft.com/en-us/library/aa290051(VS.71).aspx
发表于 2008-10-22 19:31 wetwoo的小窝 阅读(248) | 评论 (0)编辑 收藏
 
http://www.microsoft.com/whdc/system/platform/server/datacenter/numa_isv.mspx
http://msdn.microsoft.com/en-us/library/aa363804.aspx
发表于 2008-10-22 17:49 wetwoo的小窝 阅读(221) | 评论 (0)编辑 收藏
 
http://www.microsoft.com/whdc/system/platform/64bit/WoW64_bestprac.mspx
发表于 2008-10-22 16:59 wetwoo的小窝 阅读(231) | 评论 (0)编辑 收藏
 
http://go.microsoft.com/fwlink/?LinkId=28022
发表于 2008-10-22 16:02 wetwoo的小窝 阅读(234) | 评论 (0)编辑 收藏

2008年10月21日

http://msdn.microsoft.com/en-us/library/ms681622(VS.85).aspx
发表于 2008-10-21 19:43 wetwoo的小窝 阅读(237) | 评论 (0)编辑 收藏
 
Condition variables are synchronization primitives that enable threads to wait until a particular condition occurs. Condition variables are user-mode objects that cannot be shared across processes.


Condition variables enable threads to atomically release a lock and enter the sleeping state. They can be used with critical sections or slim reader/writer (SRW) locks. Condition variables support operations that "wake one" or "wake all" waiting threads. After a thread is woken, it re-acquires the lock it released when the thread entered the sleeping state.

The following pseudocode demonstrates the typical usage pattern of condition variables.


CRITICAL_SECTION CritSection;
CONDITION_VARIABLE ConditionVar;

void PerformOperationOnSharedData()
{
EnterCriticalSection(&CritSection);

// Wait until the predicate is TRUE

while( TestPredicate() == FALSE )
{
SleepConditionVariableCS(&ConditionVar, &CritSection, INFINITE);
}

// The data can be changed safely because we own the critical
// section and the predicate is TRUE

ChangeSharedData();

LeaveCriticalSection(&CritSection);

// If necessary, signal the condition variable by calling
// WakeConditionVariable or WakeAllConditionVariable so other
// threads can wake
}

For example, in an implementation of a reader/writer lock, the TestPredicate function would verify that the current lock request is compatible with the existing owners. If it is, acquire the lock; otherwise, sleep. For a more detailed example, see Using Condition Variables.

Condition variables are subject to spurious wakeups (those not associated with an explicit wake) and stolen wakeups (another thread manages to run before the woken thread). Therefore, you should recheck a predicate (typically in a while loop) after a sleep operation returns.

You can wake other threads using WakeConditionVariable or WakeAllConditionVariable either inside or outside the lock associated with the condition variable. It is usually better to release the lock before waking other threads to reduce the number of context switches.

It is often convenient to use more than one condition variable with the same lock. For example, an implementation of a reader/writer lock might use a single critical section but separate condition variables for readers and writers.

发表于 2008-10-21 12:30 wetwoo的小窝 阅读(218) | 评论 (0)编辑 收藏
 
Slim reader/writer (SRW) locks enable the threads of a single process to access shared resources; they are optimized for speed and occupy very little memory.


Reader threads read data from a shared resource whereas writer threads write data to a shared resource. When multiple threads are reading and writing using a shared resource, exclusive locks such as a critical section or mutex can become a bottleneck if the reader threads run continuously but write operations are rare.


SRW locks provide two modes in which threads can access a shared resource:

Shared mode grants shared read-only access to multiple reader threads, which enables them to read data from the shared resource concurrently. If read operations exceed write operations, this concurrency increases performance and throughput compared to critical sections.
Exclusive mode grants read/write access to one writer thread at a time. When the lock has been acquired in exclusive mode, no other thread can access the shared resource until the writer releases the lock.

A single SRW lock can be acquired in either mode; reader threads can acquire it in shared mode whereas writer threads can acquire it in exclusive mode. There is no guarantee about the order in which threads that request ownership will be granted ownership; SRW locks are neither fair nor FIFO.

An SRW lock is the size of a pointer. The advantage is that it is fast to update the lock state. The disadvantage is that very little state information can be stored, so SRW locks cannot be acquired recursively. In addition, a thread that owns an SRW lock in shared mode cannot upgrade its ownership of the lock to exclusive mode.
发表于 2008-10-21 12:19 wetwoo的小窝 阅读(222) | 评论 (0)编辑 收藏

2008年10月20日

http://www.microsoft.com/whdc/system/platform/firmware/bcd.mspx
发表于 2008-10-20 20:35 wetwoo的小窝 阅读(302) | 评论 (0)编辑 收藏