<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent changes to bugs</title><link href="https://sourceforge.net/p/threadpool/bugs/" rel="alternate"/><link href="https://sourceforge.net/p/threadpool/bugs/feed.atom" rel="self"/><id>https://sourceforge.net/p/threadpool/bugs/</id><updated>2012-05-10T11:17:44Z</updated><subtitle>Recent changes to bugs</subtitle><entry><title>Eventual pthread resource exhaustion uncaught exception</title><link href="https://sourceforge.net/p/threadpool/bugs/7/" rel="alternate"/><published>2012-05-10T11:17:44Z</published><updated>2012-05-10T11:17:44Z</updated><author><name>Andrew McDonnell</name><uri>https://sourceforge.net/u/andymc73/</uri></author><id>https://sourceforge.net30602a74c69a14393eb0e148470425b9be05ef86</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;(Affects pthreads i.e. Linux implementation of boost)&lt;br /&gt;
In a situation where pools are being continually created and destroyed, the terminate_all_workers() doesnt properly join all the threads that were created by the pool.&lt;br /&gt;
As a result, eventually pthread_create() will fail inside the  worker_thread&amp;lt;pool_type&amp;gt;::create_and_attach() &lt;br /&gt;
Because this is silent, instead, the next pool created deadlocks waiting for a condition that will never be sent because there was no thread created to send it but the pool doesnt realise this because it doesnt properly detect creation errors.&lt;/p&gt;
&lt;p&gt;On a linux x86-64 OpenSuse 11.4 with intel 8 core CPU, this occurs after 2752 unjoined threads exist.&lt;br /&gt;
On a linux amd64 phenom quad core debian squeeze, there seems to have been 32768 unjoined threads created&lt;/p&gt;
&lt;p&gt;There are two problems:&lt;br /&gt;
(a) the resource exeption within create_and_attach() is silently trapped. This caused me a lot of head scratching for a while...&lt;br /&gt;
(b) the terminate_all_workers method() does not join all exiting threads, because it runs before the thread destruction hook worker_destructed() has a chance to add the thread to the terminated_workers vector &lt;/p&gt;
&lt;p&gt;I resolved this by counting the number of times the thread creation is called for the pool, and using that to make sure that many threads are waiting to be cleaned up before exiting.&lt;/p&gt;
&lt;p&gt;Update: after I fixed this problem, I read bug 2910301 and suspect it is the same problem. I also think  the fix supplied is just as valid as what worked for me.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;I would still class eating the resource exception as an additional bug, the caller should know if it is not possible to create the pool in the desired manner.&lt;/p&gt;
&lt;p&gt;To demonstrate the problem using unpatched 0.2.5:&lt;/p&gt;
&lt;p&gt;(Run the example)&lt;br /&gt;
g++ -I threadpool-0_2_5-src/threadpool/ -lboost_thread -lpthread example.cpp&lt;br /&gt;
./a.out&lt;/p&gt;
&lt;p&gt;After 172 iterations thread creation failed as 2562 threads were finished but never joined&lt;br /&gt;
because the exception is silently caught, output of 'task' stops after 172&lt;br /&gt;
when I inserted 'throw' in the handler, instead after 172 iterations the program aborted&lt;/p&gt;
&lt;p&gt;On a different computer, amd64 debian squeeze, I managed 2047 loops instead&lt;/p&gt;
&lt;p&gt;After my patch, this runs to completion&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Error in pool destruction</title><link href="https://sourceforge.net/p/threadpool/bugs/6/" rel="alternate"/><published>2010-10-20T20:59:45Z</published><updated>2010-10-20T20:59:45Z</updated><author><name>gmit</name><uri>https://sourceforge.net/u/gmit2/</uri></author><id>https://sourceforge.net5a58ddb32730650e027ef0599b03817fc73c22b3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello. I have the following set of events:&lt;/p&gt;
&lt;p&gt;1. I have a .dll that uses fifo_pool.&lt;/p&gt;
&lt;p&gt;2. Pool gets destructed.&lt;/p&gt;
&lt;p&gt;2.1. terminate_all_workers (wait_for_all_tasks shutdown policy) notify all workers to quit.&lt;/p&gt;
&lt;p&gt;2.2. All workers were already finished with their tasks, so, there's no wait&lt;/p&gt;
&lt;p&gt;2.3.1. Worker threads gets notification they should be quit, they clean up and, at the end, they add themselves to the m_terminated_workers collection&lt;/p&gt;
&lt;p&gt;2.3.2. Back in terminate_all_workers; m_terminated_workers collection is iterated and all threads there are joined. However, at this point, m_terminated_workers collection IS EMPTY. The sequence was notify all and then no wait, so, threads are ready to be run, but, they are possibly not scheduled yet.&lt;/p&gt;
&lt;p&gt;2.4. Pool destructor is done.&lt;/p&gt;
&lt;p&gt;3. My dll is unloaded.&lt;/p&gt;
&lt;p&gt;4. Worker threads eventually get scheduled and BOOM - process crashes because there's no more code to execute.&lt;/p&gt;
&lt;p&gt;Does this explanation makes any sense? Is there a fix for this? Tnx.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>unusable shutdown policy</title><link href="https://sourceforge.net/p/threadpool/bugs/5/" rel="alternate"/><published>2010-02-19T02:26:07Z</published><updated>2010-02-19T02:26:07Z</updated><author><name>Anonymous</name><uri>https://sourceforge.net/u/userid-None/</uri></author><id>https://sourceforge.net60787418cef9b63f575a93a6be5167b3525e16a4</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm wondering how to shutdown the thread pool. I have used the shutdown policy, but it can't work because the "void terminate_all_workers(bool const wait)" function is a private member function.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Memory Leak fix</title><link href="https://sourceforge.net/p/threadpool/bugs/4/" rel="alternate"/><published>2009-12-07T21:35:56Z</published><updated>2009-12-07T21:35:56Z</updated><author><name>Anton Matosov</name><uri>https://sourceforge.net/u/shikin/</uri></author><id>https://sourceforge.net686b9e43acfd89f611b50e1fa95af48241cc262f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have fixed the memory leak issue which exists in the version 0.2.5, Fixed version of 0.2.5 you can find in the attachment.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Memory leak</title><link href="https://sourceforge.net/p/threadpool/bugs/3/" rel="alternate"/><published>2009-09-22T17:43:50Z</published><updated>2009-09-22T17:43:50Z</updated><author><name>Michael Moritz</name><uri>https://sourceforge.net/u/mimo/</uri></author><id>https://sourceforge.net8eb81b8c87f5ae1cebebd1e00d6e315ce51e354f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Here is the valgrind output from the threadpool specific part of my daemon which grows to about 3G in an hour. Any help appreciated.&lt;/p&gt;
&lt;p&gt;==11428== Thread 1:&lt;br /&gt;
==11428==&lt;br /&gt;
==11428== 7,200 bytes in 50 blocks are possibly lost in loss record 13 of 14&lt;br /&gt;
==11428==    at 0x4021E22: calloc (vg_replace_malloc.c:397)&lt;br /&gt;
==11428==    by 0x4010C7B: _dl_allocate_tls (in /lib/ld-2.7.so)&lt;br /&gt;
==11428==    by 0x42CF672: pthread_create@@GLIBC_2.1 (in /lib/i686/cmov/libpthread-2.7.so)&lt;br /&gt;
==11428==    by 0x4045F76: boost::thread::start_thread() (in /usr/lib/libboost_thread-mt.so.1.35.0)&lt;br /&gt;
==11428==    by 0x80E0CC7: boost::thread::thread&amp;lt;boost::_bi::bind_t&amp;lt;void, boost::_mfi::mf0&amp;lt;void, boost::threadpool::detail::worker_thread&amp;lt;boost::threadpool:&lt;br /&gt;
:detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::&lt;br /&gt;
threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt; &amp;gt; &amp;gt;, boost::_bi::list1&amp;lt;boost::_bi::value&amp;lt;boost::shared_ptr&amp;lt;boost::threadpool::detail::&lt;br /&gt;
worker_thread&amp;lt;boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::&lt;br /&gt;
threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt;(boost::_bi::bind_t&amp;lt;void, boost::_mfi::mf0&amp;lt;&lt;br /&gt;
void, boost::threadpool::detail::worker_thread&amp;lt;boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::th&lt;br /&gt;
readpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt; &amp;gt; &amp;gt;, boost::_bi::list&lt;br /&gt;
1&amp;lt;boost::_bi::value&amp;lt;boost::shared_ptr&amp;lt;boost::threadpool::detail::worker_thread&amp;lt;boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;bo&lt;br /&gt;
ost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_&lt;br /&gt;
all_tasks&amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt; &amp;gt;) (thread.hpp:151)&lt;br /&gt;
==11428==    by 0x80E0DE4: boost::threadpool::detail::worker_thread&amp;lt;boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt;&amp;gt;::create_and_attach(boost::shared_ptr&amp;lt;boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt; &amp;gt; const&amp;amp;) (worker_thread.hpp:105)&lt;br /&gt;
==11428==    by 0x80E4B93: boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt;::resize(unsigned) volatile (pool_core.hpp:349)&lt;br /&gt;
==11428==    by 0x80E4B93: boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt;::resize(unsigned) volatile (pool_core.hpp:349)&lt;br /&gt;
==11428==    by 0x80E5187: boost::threadpool::static_size&amp;lt;boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt; &amp;gt;::init(boost::threadpool::detail::pool_core&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt;&amp;amp;, unsigned) (size_policies.hpp:75)&lt;br /&gt;
==11428==    by 0x80E59EF: boost::threadpool::thread_pool&amp;lt;boost::function0&amp;lt;void, std::allocator&amp;lt;boost::function_base&amp;gt; &amp;gt;, boost::threadpool::fifo_scheduler,boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks&amp;gt;::thread_pool(unsigned) (pool.hpp:103)&lt;br /&gt;
==11428==    by 0x80E5D97: Server::Server(int volatile&amp;amp;, boost::shared_ptr&amp;lt;FileDescriptor&amp;gt;, boost::shared_ptr&amp;lt;Core&amp;gt;, unsigned, unsigned, unsigned, unsigned, unsigned, bool, std::string const&amp;amp;, std::string const&amp;amp;, std::string const&amp;amp;, unsigned) (server.h:84)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Memory leak on Windows</title><link href="https://sourceforge.net/p/threadpool/bugs/2/" rel="alternate"/><published>2009-04-06T00:18:37Z</published><updated>2009-04-06T00:18:37Z</updated><author><name>Anonymous</name><uri>https://sourceforge.net/u/userid-None/</uri></author><id>https://sourceforge.netabefcca9c785a00a4575b9247dcc56ceeeca1ef1</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Using Visual Studio 9, we have detected memory leaks when using the threadpool library. Unfortunately, we do not have the time right now to debug it for you, so I am posting this in the hopes that you can take a look and maybe it is a quick fix for you. Basically, this method:&lt;/p&gt;
&lt;p&gt;static void create_and_attach(shared_ptr&amp;lt;pool_type&amp;gt; const &amp;amp; pool)&lt;br /&gt;
{&lt;br /&gt;
shared_ptr&amp;lt;worker_thread&amp;gt; worker(new worker_thread(pool));&lt;br /&gt;
if(worker)&lt;br /&gt;
{&lt;br /&gt;
worker-&amp;gt;m_thread.reset(new boost::thread(bind(&amp;amp;worker_thread::run, worker)));&lt;br /&gt;
}&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;creates new worker threads. As best I can tell, this is where the memory is being leaked. It looks like the worker and/or the pool are not getting released properly. I looked through and see that you are using shared pointers, so maybe the reference count is not getting decremented properly. Again, I haven't had the time to look more closely at it. To reproduce, basically just use this code (run it from Visual Studio):&lt;/p&gt;
&lt;p&gt;#include &amp;lt;boost/threadpool.hpp&amp;gt;&lt;/p&gt;
&lt;p&gt;#ifdef WIN32&lt;br /&gt;
#include &amp;lt;crtdbg.h&amp;gt;&lt;br /&gt;
#endif&lt;/p&gt;
&lt;p&gt;int main()&lt;br /&gt;
{&lt;br /&gt;
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );&lt;/p&gt;
&lt;p&gt;boost::threadpool::pool pool( 1 );&lt;/p&gt;
&lt;p&gt;return 0;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;Please let me know if you need any clarification or additional information. Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>hangs up in boost::threadpool::pool::~pool</title><link href="https://sourceforge.net/p/threadpool/bugs/1/" rel="alternate"/><published>2008-05-20T09:49:27Z</published><updated>2008-05-20T09:49:27Z</updated><author><name>Anonymous</name><uri>https://sourceforge.net/u/userid-None/</uri></author><id>https://sourceforge.net1dfb690efb53377f899b90827e42c51bcf0cfbd0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I am using threadpool with Boost 1.35 and it hangs up when I try to destroy boost::threadpool::pool object.&lt;br /&gt;
Debugging shows that none of my functions are executing.&lt;br /&gt;
The problem seems to be that one of the worker threads doesn't get m_task_or_terminate_workers_event event.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>