您的位置:首页 > 其它

关于线程的两篇文章

2008-01-06 15:50 387 查看
1.Extended Threading: Do More with the Same Thread

让一个线程完成更多的任务。作者自己写了一个类,拦截System.Threading.Thread,试图让你在不同的线程执行同一个方法成为可能,如果你想执行多次,你不必每次都创建一个新线程来执行该方法,优势在于提高性能并且易于使用,毕竟创建线程的代价还是比较昂贵的。

作者完成了一个Demo,用自己实现的方案分别对普通线程,线程池实现方式的性能作了比较。

Download demo project - 8.3 KB
Download source - 16 KB

2.Smart Thread Pool

智能线程池。该线程池不同于.net framework提供的线程池,这个线程池完全重新实现,并增加了很多有用的特性。

The number of threads dynamically changes according to the workload on the threads in the pool.

Work items can return a value.
A work item can be cancelled if it hasn't been executed yet.
The caller thread's context is used when the work item is executed (limited).
Usage of minimum number of Win32 event handles, so the handle count of the application won't explode.
The caller can wait for multiple or all the work items to complete.
Work item can have a
PostExecute
callback, which is called as soon the work item is completed.
The state object, that accompanies the work item, can be disposed automatically.
Work item exceptions are sent back to the caller.
Work items have priority.
Work items group.
The caller can suspend the start of a thread pool and work items group.
Threads have priority.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: