从智能线程池中删除空闲线程的正确方法 [英] Right way to delete the idle threads from a smart thread pool

查看:470
本文介绍了从智能线程池中删除空闲线程的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用C#智能线程池做一些工作,但发现当前的智能线程池释放没有任何关于删除的空闲线程。这可能会也可能不会导致智能线程池内存泄漏。



smartthreadpool.ProcessQueueItem()方法中当空闲线程超时时,方法会多次调用 InforComleted()方法。但是 InformCompleted()只是从字典中删除了线程并且没有删除这些线程:

I have been using the C# smart thread pool to do some work but found the current smart thread pool release DOES NOT anything about the removed "idle threads". This may or may not cause smart thread pool memory leaks.

In the smartthreadpool.ProcessQueueItem() method there are several times the method calls InforComleted() method when a idle thread(s) is timed out. But the InformCompleted() just removes the thread from the dictionary and didn''t the delete these threads:

private void InformCompleted()
{
   if(_workerThreads.Contains(Thread.CurrentThread))
   {
      _workerThreads.Remove(Thread.CurrentThread);
   }
}



我想知道是否有人已经解决了这个问题并测试了它。



非常感谢。



祝你好运,

CodeBeetle123


I''m wondering if there is anyone out there already solved this problem and test it out.

Thank you very much.

Best regards,
CodeBeetle123

推荐答案

通常,你不要从池中删除线程。他们坐在那里闲着,等待工作这样做你不会产生旋转新线程的相当大的开销!



如果你有有关特定库的问题,请联系该库的作者。仅仅因为你在一篇文章中看到它并不意味着这里的每个人都知道你在说什么,并且在每篇文章中都使用了每一段代码。
Normally, you DON''T remove threads from the pool. They sit there idle, waiting for work to do so you don''t incur the rather large overhead of spinning a new thread up!

If you''ve got questions about a particular library, you contact the author of that library. Just because you saw it in an article here does NOT mean that everyone around here knows exactly what you''re talking about and has used every bit of code in every article.


这篇关于从智能线程池中删除空闲线程的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆