天天看點

重新想象 Windows 8 Store Apps (48) - 多線程之其他輔助類: SpinWait, SpinLock, Volatile, SynchronizationContext, CoreDispatcher, ThreadLocal, ThreadStaticAttribute

<a href="http://files.cnblogs.com/webabcd/Windows8.rar">[源碼下載下傳]</a>

重新想象 Windows 8 Store Apps (48) - 多線程之其他輔助類: SpinWait, SpinLock, Volatile, SynchronizationContext, CoreDispatcher, ThreadLocal, ThreadStaticAttribute

介紹

重新想象 Windows 8 Store Apps 之 多線程操作的其他輔助類

SpinWait - 自旋等待

SpinLock - 自旋鎖

volatile - 必在記憶體

SynchronizationContext - 在指定的線程上同步資料

CoreDispatcher - 排程器,用于線程同步

ThreadLocal - 用于儲存每個線程自己的資料

ThreadStaticAttribute - 所指定的靜态變量對每個線程都是唯一的

示例

1、示範 SpinWait 的使用

Thread/Other/SpinWaitDemo.xaml.cs

2、示範 SpinLock 的使用

Thread/Other/SpinLockDemo.xaml.cs

3、示範 volatile 的使用

Thread/Other/VolatileDemo.xaml

4、示範 SynchronizationContext 的使用

Thread/Other/SynchronizationContextDemo.xaml.cs

5、示範 CoreDispatcher 的使用

Thread/Other/CoreDispatcherDemo.xaml.cs

6、示範 ThreadLocal 的使用

Thread/Other/ThreadLocalDemo.xaml.cs

7、示範 ThreadStaticAttribute 的使用

Thread/Other/ThreadStaticAttributeDemo.xaml.cs

OK