[AGENT++] [PATCH] agent++: locking fixes and improvements
dominik.vogt at external.thalesgroup.com
dominik.vogt at external.thalesgroup.com
Wed Aug 18 09:58:22 CEST 2010
On Tue, Aug 17, 2010 at 10:24:47PM +0200, Jochen Katz wrote:
> > This fixes a race condition or crash caused by unlocking the mib
> > in the wrong place (there are three nested loops; the lock is
> > managed in the second loop, but the particular unlock takes
> > place right before the inner loop is restarted).
>
> maybe it is already too late, but I cannot find a way through the code
> where the lock is not locked when this unlock/continue is called.
The code is structured like this:
for (/*outer loop*/)
{
for (/*middle loop*/)
{
A lock_mib()
do
{
B ... <------------------
if (/*something*/) |
{ | inner loop condition ture
C unlock_mib(); |
D continue; ---------------
} |
... | inner loop condition false
} while (/*inner loop*/); |
E ... <-------------------------
F unlock_mib();
...
}
}
1. The program first enters the middle loop, it locks the Mib at
A and then enters the inner loop.
2. At the beginning of the inner loop (B), the Mib is locked.
3. The program reaches C inside the inner loop and unlocks the
Mib.
4. At D, the program jumps to the end of the inner loop and either
breaks the inner loop and proceeds with E (if the condition is
false) or restarts the *inner* loop and jumps to B.
5. If it jumps to B, the inner loop is now running *without* the
lock. If it proceeds with E, it eventually reaches F and tries
to unlock the Mib although it is not locked.
With posix mutexes it would not do any harm to unlock a mutex
twice that was locked exactly once. But it *does* harm to run the
inner loop without the lock.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
More information about the AGENTPP
mailing list