19
27.6 异步实现服务器 ··············································································································· 552
27.7 APM 和计算限制操作 ······································································································· 553
27.8 APM 的注意事项 ·············································································································· 554
27.8.1 在没有线程池的前提下使用 APM ················································································· 554
27.8.2 总是调用 EndXxx 方法,而且只调用一次 ···································································· 555
27.8.3 调用 EndXxx 方法时总是使用相同的对象 ···································································· 555
27.8.4 为 BeginXxx 和 EndXxx 方法使用 ref,out 和 params 实参 ·········································· 556
27.8.5 不能取消异步 I/O 限制操作 ··························································································· 556
27.8.6 内存消耗 ························································································································· 556
27.8.7 有的 I/O 操作必须同步完成 ··························································································· 556
27.8.8 FileStream 特有的问题 ··································································································· 557
27.9 I/O 请求优先级 ················································································································· 557
27.10 将 IAsyncResult APM 转换为 Task ··················································································· 559
27.11 基于事件的异步模式 ······································································································ 560
27.11.1 将 EAP 转换为 Task ······································································································· 562
27.11.2 APM 和 EAP 的对比······································································································· 563
27.12 编程模型的泥沼 ············································································································· 563
第 28 章 基元线程同步构造 ······································································ 565
28.1 类库和线程安全 ··············································································································· 566
28.2 基元用户模式和内核模式构造························································································· 567
28.3 用户模式构造 ··················································································································· 568
28.3.1 易失构造 ························································································································· 568
28.3.2 互锁构造 ························································································································· 572
28.3.3 实现简单的 Spin Lock ····································································································· 576
28.3.4 Interlocked Anything 模式 ······························································································· 578
28.4 内核模式构造 ··················································································································· 579
28.4.1 Event 构造 ······················································································································· 582
28.4.2 Semaphore 构造 ·············································································································· 584
28.4.3 Mutex 构造 ······················································································································ 584
28.4.4 在一个内核构造可用时调用一个方法 ·········································································· 586
第 29 章 混合线程同步构造 ······································································ 588
29.1 一个简单的混合锁 ············································································································ 588
29.2 自旋、线程所有权和递归 ································································································ 589
29.3 混合构造的大杂烩 ············································································································ 591