并发的任务分工

Here are the ways to reap the benefits of multicore processors:
• We have to divide the application into multiple tasks that can be run concurrently.
• We should choose at least as many threads as the number of cores, provided the problem is large enough to benefit from those many threads.
• For computationally intensive applications, we should limit the number of threads to the number of cores.
• For IO-intense applications, the time spent blocking influences the number of threads we’d create.
• Estimate the number of threads using the following formula:
Number of threads = Number of Available Cores / (1 - Blocking Coefficient)
where 0 ≤ blocking coefficient < 1.
• We should slice the problem into several parts so there is enough work for cores and they’re utilized well.
• We must avoid shared mutable state and instead use either isolated mutability or shared immutability.
• We should make good use of the modern threading API and thread pools.
posted @ 2012-02-21 11:09  Colin_Ye  阅读(213)  评论(0编辑  收藏  举报