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

Frank Fock fock at agentpp.com
Tue Sep 12 00:16:09 CEST 2017


Hi Claus,

The QueuedThreadPool was never intended for the API end user.
Therefore, it is not documented at all. 
The start() method cannot be called in the constructor because a thread should never be started in a constructor.
The set_stack_size() method you are calling does set the stack size of the queue thread and not the stack size of the worker threads. The naming clash is surely not wanted but was induced by the inheritance (which could have been avoided by composition instead inheritance).

You are testing an empty thread pool (no worker threads) but expect to have all assigned tasks being run. That is a contradiction and not a bug of the code. 

Best regards,
Frank 


> On 11. Sep 2017, at 20:48, Claus Klein <claus.klein at arcormail.de> wrote:
> 
> 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?
> 
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> https://oosnmp.net/mailman/listinfo/agentpp



More information about the AGENTPP mailing list