"Scalable Multithreaded Programming with Thread Pools" 阅读笔记

(MSDN Magzine 上的文章 )

 

"There are many different ways to distribute your work across multiple cores. One of the easiest and most robust is called task-based programming."

"To achieve this state of multicore bliss, you’ll have to reexamine some of your preconceptions of how to attack a programming problem and rethink them in terms of task-based programming."

 

From Threads to Tasks

"

There are a few guidelines to keep in mind when converting a large single-threaded job into multithreaded tasks:

  • The large job can be arbitrarily divided into 1 to n tasks.
  • The tasks should be able to run in any order.
  • The tasks should be independent of each other.
  • The tasks must have associated context data.

 

Using the Thread Pool

"Threads require a lot of bookkeeping by the OS, so it’s not a good idea to wantonly create and destroy them. There are not-insignificant costs associated with creating and destroying a thread, so if you do this constantly, it’s easy to lose any advantage you gain by multithreading."

 

"The advantage of using a thread pool instead of creating your own threads is that the OS will take care of scheduling tasks for you—your job will be to keep feeding tasks into the thread pool so that the OS will be able to keep all of the hardware threads busy."

 

本来期待这篇文章能介绍 Thread Pool 的机制及调用建议, 结果往后面一看, 发现转到以快速排序为例子讲如何切分 task 去了, 没什么意思.

不过文章前面介绍基本原则的地方多少还是值得一看.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值