[AGENT++] Why need the Agentpp::Synchronized class a pthread_cond_t cont member?

Claus Klein claus.klein at arcormail.de
Sat Nov 17 08:02:41 CET 2018


Hi Frank,

Ok, I say it again:

At the current code, the wait() is waiting for as signal, but does not know the condition the application is waiting for!
Too it is not asserted, that the mutex is locket, but this is required!

So it is possible, it is waiting for a state, that is already reached, i.e. queue not empty.

void LockQueue::run()
{
    lock();
    while ((!pendingLock.empty()) || (!pendingRelease.empty()) || (go)) {
…
        // do not wait forever because we cannot
        // be sure that all instrumentation code notifies
        // us correctly.
        wait(5000);
    }
…
}
// ATTENTION: this code is not exception save! CK

> Am 16.11.2018 um 23:43 schrieb Frank Fock <fock at agentpp.com>:
> 
> What problem/issue are you trying to fix?
There are race conditions in your code!

> Are you trying to improve performance or stability?
The code is not exception save!

> If the latter, did you find any race condition in the existing code?
I have send you lots of examples!

see https://en.cppreference.com/w/cpp/language/raii

References

	• ↑ RAII in Stroustrup's C++ FAQ
	• ↑ C++ Core Guidelines E.6 "Use RAII to prevent leaks"

====================
// Waiting should like that:
void LockQueue::run()
{
    Lock l(*this);
    while ((!pendingLock.empty()) || (!pendingRelease.empty()) || (go)) {
        cont.wait(l);	// NOTE: not possible at the moment! CK
    }
…
}
====================

Regards
Claus



More information about the AGENTPP mailing list