[AGENT++] slightly change design to prevent deadlocks and race conditions at Agentpp::ThreadPool

Claus Klein claus.klein at arcormail.de
Sun Dec 9 21:54:14 CET 2018


Hi all

If you are interested, I have published my improved implementation and test suite for the Agentpp::ThreadPool Classes.

With this Version, it is possible to use the code in an exception save way like this:

void TaskManager::run()
{
    scoped_lock l(mutex);
    //=================================
    tid_ = boost::this_thread::get_id();

    DTRACE("");
    while (go) {
        wait_until_condition(l, boost::bind(&TaskManager::has_task, this));

        if (!go)
            break;

        if (task) {
            try {
                //=====================================
                task->run();
                //=====================================
            } catch (std::exception& e) {
                DTRACE(e.what());
            } catch (...) {
                // TODO: log ... but ignored! CK
            }
            delete task;
            task = 0;
            threadPool->idle_notification();
        }
    }

    if (task) {
        delete task;
        task = 0;
        DTRACE("task deleted after stop()");
    }

    tid_ = boost::thread::id();
    //=================================
}




https://github.com/ClausKlein/ThreadPool/commit/accb60a9c76b0205e771ffb3a3b924f622a469b2 <https://github.com/ClausKlein/ThreadPool/commit/accb60a9c76b0205e771ffb3a3b924f622a469b2>

With regards,

Claus Klein


„Es ist nicht genug, zu wissen, man muß auch anwenden; 
     es ist nicht genug, zu wollen, man muß auch tun.“ 
Johann Wolfgang von Goethe <http://www.zitate-online.de/autor/goethe-johann-wolfgang-von/> (Werk: Wilhelm Meisters Wanderjahre)



More information about the AGENTPP mailing list