《Pro .Net 4 Parallel Programming in C#》笔记

《Pro .Net 4 Parallel Programming in C#》笔记

$ 周期性定时任务用

CancellationToken.WaitHandle.WaitOne(TimeSpan)

 特点:如果Task被Cancel,WaitOne马上就会返回。

 

$ 同步元

同步元选择
场景解决方案
串行访问边界区域lock关键字或System.Threading.Monitor或System.Threading.SpinLock
增加或减少数值System.Threading.Mutex
跨进程同步System.Threading.Mutex
多个锁的同步Threading.WaitHandle.WaitAll()
同步类中的所有方法声明式的同步([Synchronization])(非常重量级)
允许多个读者读写锁

 

同步元说明
lockSystem.Threading.Monitor的缩写形式,重量级
System.Threading.Barrier预先设定信号数量,有足够信号量后继续执行。自动重置
System.Threading.CountdownEvent类似Barrier,但是需要主动重置
System.Threading.ManualResetEventSlim类似CountdownEvent,但是不设定信号数量,一旦Set,所有等待线程被释放
System.Threading.AutoResetEvent类似ManualResetEventSlim,但自动重置,每次Set只释放一个等待线程,不能使用CancellationToken等待,不保证哪个线程被释放
System.Threading.SemaphoreSlim类似AutoResetEvent,同样不保证哪个线程被释放,但可以指定每次Set所释放的线程数,可以用CancellationToken等待

 

$ TaskScheduler用于指定由哪个线程执行Task,以及并发Task的数量和顺序

 

$ 利用Thread Local Storage(TLS,Parallel.For) 可减少对竞态数据的访问,只在每个分支线程结束时访问,从而提高性能。

 

$ 当操作很简单时,可以通过指定数据的分块模式(chunking partitioner),来降低调用委托(delegate)的开销。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Wrox Press 2010出版,并行编程+c#,提供给感兴趣的朋友 In 2007, Microsoft released the fi rst Community Technology Preview (CTP) of Parallel Extensions for the .NET Framework. The old .NET Framework multithreading programming model was too complex and heavyweight for the forthcoming multicore and manycore CPUs. I had been researching parallel programming, multiprocessor, and multicore since 1997, so I couldn’t help installing the fi rst CTP and trying it. It was obvious that it was going to be an exciting new way of expressing parallelism in future C# versions. Visual Studio 2010 ships with version 4 of the .NET Framework, the fi rst release to include Parallel Extensions. C# 4 and .NET Framework 4 allow you to shift to a modern task-based programming model to express parallelism. It is easier to write code that takes advantage of multicore microprocessors. Now, you can write code that scales as the number of available cores increases, without having to work with complex managed threads. You are able to write code that runs tasks, and the Common Language Runtime (CLR) will inject the necessary threads for you. It is easy to run data parallelism algorithms taking advantage of multicore. At the time of this writing, multicore microprocessors are everywhere. Servers, desktop computers, laptops and notebooks, netbooks, mobile Internet devices (MIDs), tablets, and even smartphones use multicore microprocessors. The average number of cores in each microprocessor is going to increase in the forthcoming years. Are you going to lose the opportunity to transform this multicore power into application performance? Parallel programming must become part of your skill set to effectively develop applications for modern hardware in C#. I spent more than three years working with the diverse versions of Parallel Extensions until Visual Studio 2010 was offi cially released. I enjoyed developing parallelized applications with C#, and I did my best to include explanations for the most common scenarios in this book. Visual Studio 2010 provides an IDE prepared for a parallel developer, and C# is an excellent fi t for the new task-based programming model. amazon Link:http://www.amazon.com/exec/obidos/ASIN/0470495995/buythisbooks-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值