Combining ThreadPool with Event

Please post support and help requests here.
Posts: 2
Joined: 24 Jul 2009, 16:01

Combining ThreadPool with Event

Postby ichijoji » 01 Oct 2009, 19:28

I'm trying to implement a kind of parallel for loop using a threadpool and events to indicate when a task is finished. My task looks something like this:

Code: Select all

class Task : public Poco::Runnable
        Poco::Event m_event;

        void run()

        void wait()

And then my loop looks like this: (Note that this is called recursively for each node in a tree of nodes)

Code: Select all

std::vector<Task*> tasks;

for ( some tasks )
    Task* task = new Task();

for ( std::vector<Task*>::iterator i = tasks.begin(); i != tasks.end(); ++i )
    delete *i;

This seems ok to me as an extremely naive implementation of a parallel for loop, but when I run it the program will chug along for a while, then hang. When it hangs, there are about 5 threads active, one waiting on the wait in Task::wait, and the others waiting with a stack trace like this:

Code: Select all

(gdb) bt
#0  0xb7ff8430 in __kernel_vsyscall ()
#1  0xb6f640e5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/
#2  0xb707c2ed in pthread_cond_wait () from /lib/tls/i686/cmov/
#3  0xb7287a5b in Poco::EventImpl::waitImpl () from /usr/lib/
#4  0xb72ecb25 in Poco::PooledThread::run () from /usr/lib/
#5  0xb72e6f2f in Poco::ThreadImpl::runnableEntry () from /usr/lib/
#6  0xb6f604ff in start_thread () from /lib/tls/i686/cmov/
#7  0xb706d49e in clone () from /lib/tls/i686/cmov/

What I think is happening is that the capacity of the thread pool is filled up with threads waiting to create more threads in the thread pool. Is this a reasonable hypothesis, and if so how can it be tested and solved?

Return to “Support”

Who is online

Users browsing this forum: No registered users and 6 guests