[AGENT++] Agentpp::QueuedThreadPool does not executes its queue entries

Claus Klein claus.klein at arcormail.de
Mon Sep 11 20:48:33 CEST 2017


Hi Frank,

yes, it does.

But IMHO the interface is not easy to understand!

Why do I have to call start() for this pool? It can be done at constructor.
And if have a call start(), I can call the stop() too. Is this intended?

There are a lot of pitfalls prepared, with this unit_test

BOOST_AUTO_TEST_CASE(QueuedThreadPoolControl_test)
{
    using namespace Agentpp;
    {
        Agentpp::QueuedThreadPool emptyThreadPool(0);
        //NOTE: should implicit done: emptyThreadPool.start();
        BOOST_CHECK(emptyThreadPool.is_idle());

        emptyThreadPool.stop();
        emptyThreadPool.set_stack_size(0x20000);
        BOOST_CHECK(emptyThreadPool.stack_size() == 0x20000);

        std::cout << "\nemptyThreadPool.size: " << emptyThreadPool.size() << std::endl;
        emptyThreadPool.execute(new TestTask("Starting ...\n"));

        emptyThreadPool.start();
        BOOST_CHECK(!emptyThreadPool.is_idle());
        size_t i = 10;
        do {
            if (i > 5) {
                emptyThreadPool.execute(new TestTask("Running " + std::to_string(10 - i) + "...\n"));
            }
            std::cout << "emptyThreadPool.queue_length: " << emptyThreadPool.queue_length() << std::endl;
            Thread::sleep(10); // ms
        } while ((--i > 0) && !emptyThreadPool.is_idle());

        //NOTE: implicit done: emptyThreadPool.terminate();
    }
    BOOST_CHECK(TestTask::task_count() == 0);
    BOOST_CHECK(TestTask::run_count() == 6);
    TestTask::reset_counter();
}

I get this result:

Claus-MBP:AgentProV4 clausklein$ ./threads_test -t QueuedThreadPoolControl
Test setup error: no test cases matching filter or all test cases were disabled
Claus-MBP:AgentProV4 clausklein$ ./threads_test -t QueuedThreadPoolControl_test
Running 1 test case...
threads_test.cpp:135: error: in "QueuedThreadPoolControl_test": check emptyThreadPool.stack_size() == 0x20000 has failed

emptyThreadPool.size: 0
emptyThreadPool.queue_length: 2
emptyThreadPool.queue_length: 3
emptyThreadPool.queue_length: 4
emptyThreadPool.queue_length: 5
emptyThreadPool.queue_length: 6
emptyThreadPool.queue_length: 6
emptyThreadPool.queue_length: 6
emptyThreadPool.queue_length: 6
emptyThreadPool.queue_length: 6
emptyThreadPool.queue_length: 6
threads_test.cpp:154: error: in "QueuedThreadPoolControl_test": check TestTask::run_count() == 6 has failed

*** 2 failures are detected in the test module "Threads"
Claus-MBP:AgentProV4 clausklein$ 

> On 11 Sep 2017, at 01:39, Frank Fock <fock at agentpp.com> wrote:
> 
> I think it would be sufficient to call 
> queuedThreadPool.start();
> In your test program to run it successfully, doesn't it?



More information about the AGENTPP mailing list