免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 8308 | 回复: 27
打印 上一主题 下一主题

请问哪位有线程池的实现例子? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-08-04 08:58 |只看该作者 |倒序浏览
在网上找到一个线程池的实现,http://lxr.webperf.org/source.cgi/server/mpm/experimental/threadpool/threadpool.c,
但是没有啥注释,还没有看懂,各位是否有更加好的实现?或者例子?谢了!

论坛徽章:
0
2 [报告]
发表于 2003-08-04 09:17 |只看该作者

请问哪位有线程池的实现例子?

补充一下,我需要的是Solaris平台上C++的threadpool实现。不过,其他平台,如果有参考价值,容易移植,也欢迎提供哦。

论坛徽章:
0
3 [报告]
发表于 2003-08-04 09:28 |只看该作者

请问哪位有线程池的实现例子?

请问一下;
为什么大家都热衷于实现线程池?

sun的文档里说每次都新建线程比维护线程池开销更小,
莫非是骗人的??

论坛徽章:
0
4 [报告]
发表于 2003-08-04 09:45 |只看该作者

请问哪位有线程池的实现例子?

原帖由 "deathbravo" 发表:
请问一下;
为什么大家都热衷于实现线程池?

sun的文档里说每次都新建线程比维护线程池开销更小,
莫非是骗人的??
   

我至少可以在网上找到上十篇文章说:

对于每个线程运行时间短、线程频繁的服务器应用,用线程池比创建线程开销小,你说的“sun的文档里说每次都新建线程比维护线程池开销更小”是在什么地方,我去确认一下,麻烦给个链接!

论坛徽章:
0
5 [报告]
发表于 2003-08-04 09:52 |只看该作者

请问哪位有线程池的实现例子?

发现一个好地方,这里的threadpool感觉提供的接口很好用,

http://www.numerik.uni-kiel.de/~rok/projects/threadpool/download.html,推荐给大家,

个人感觉比http://lxr.webperf.org/source.cgi/server/mpm/experimental/threadpool/threadpool.c提供的接口要简单易懂,各位有什么高见,没有更加好的东东,我就准备用前者了。

论坛徽章:
0
6 [报告]
发表于 2003-08-04 10:02 |只看该作者

请问哪位有线程池的实现例子?

ftp://docs-pdf.sun.com/806-5257/806-5257.pdf
233页第5行,
我并不是说你骗人呀;
我就是想问一问是不是sun在骗人

论坛徽章:
0
7 [报告]
发表于 2003-08-04 11:12 |只看该作者

请问哪位有线程池的实现例子?

刚才查阅了一下,确有其事, 究竟是哪种理论正确。不知是否有人做过实验?不知版主是否能给出个权威答案?

SUN文档的原文如下:
Creating and Using Threads
The threads packages will cache the threads data structure, stacks, and LWPs so that
the repetitive creation of unbound threads can be inexpensive.

Unbound thread creation has considerable overhead when compared to process
creation or even to bound thread creation. In fact, the overhead is similar to unbound
thread synchronization when you include the context switches to stop one thread
and start another.
So, creating and destroying threads as they are required is usually better than
attempting to manage a pool of threads that wait for independent work.
A good example of this is an RPC server that creates a thread for each request and
destroys it when the reply is delivered, instead of trying to maintain a pool of
threads to service requests.
While thread creation has less overhead compared to that of process creation, it is
not efficient when compared to the cost of a few instructions. Create threads for
processing that lasts at least a couple of thousand machine instructions.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
8 [报告]
发表于 2003-08-04 11:54 |只看该作者

请问哪位有线程池的实现例子?

我说一下我的理解。

线程创建的代价很低,所以文档上说,即时创建线程的代价不见得比管理一个pool的代价高。相比之下,由于即时创建进程的代价太大,所以比进程池的模式性能要差很多。

我觉得不能孤立的来比较这两种机制。设计上,尽量将任务划分位独立的不同部分,分别由不同的线程(进程)来并发处理,尽量消除瓶颈,才是提高性能的关键。

单从并发处理任务的性能上来说,费时间的任务,性能不会相差很多。至于小的任务,并发请求超多的情况下,如果pool的管理效率高的话,应该是pool的性能好些,但是并发请求并不太高的情况下,也不会明显。

论坛徽章:
0
9 [报告]
发表于 2003-08-04 12:04 |只看该作者

请问哪位有线程池的实现例子?

原帖由 "gadfly" 发表:
我说一下我的理解。

线程创建的代价很低,所以文档上说,即时创建线程的代价不见得比管理一个pool的代价高。相比之下,由于即时创建进程的代价太大,所以比进程池的模式性能要差很多。

我觉得不能孤立的来比较..........
   

我觉得你的理论有道理,但是你的翻译不准确,
creating and destroying threads as they are required is usually better than
attempting to manage a pool of threads that wait for independent work.

这句话的意思是:
“创建和销毁进程的代价通常比线程池管理要代价小,因为线程池管理需要额外的工作。”,

并不是您的意思:
“即时创建线程的代价不见得比管理一个pool的代价高”,我觉得,这些英文的意思和你的观点是相对的。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
10 [报告]
发表于 2003-08-04 12:37 |只看该作者

请问哪位有线程池的实现例子?

呵呵。
这个需要测试才知道。没对比过,所以我不能绝对的下结论,加入了我的一些理解。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP