Severe but difficult to diagnose lock error in qpid::sys::StateMonitor
----------------------------------------------------------------------

                 Key: QPID-3199
                 URL: https://issues.apache.org/jira/browse/QPID-3199
             Project: Qpid
          Issue Type: Bug
          Components: C++ Broker, C++ Client
    Affects Versions: 0.8, 0.9
            Reporter: Andrew Stitcher
            Assignee: Andrew Stitcher
             Fix For: 0.10


The qpid::sys::StateMonitor class has 4 member functions liker this:
  void waitFor(Enum s) { ScopedWait(*this); while (s != state) wait(); }

However the ScopeWait(*this); is in error, because it creates a temporary 
ScopedWait and then immediately destroys it. Instead of locking this and then 
unlocking it at the end of the function execution.

What was meant was:
  void waitFor(Enum s) { ScopedWait w(*this); while (s != state) wait(); }

which creates a local variable w which is destroyed at the end of the function 
execution unlocking this.

It is possible that the compiler/options we use do not actually exhibit this 
bug or at least only with some options as this correct behaviour, may not 
actually be implemented by all compilers.

If this bug exhibits it might show as StateMonitor::waitFor() never detecting 
the desired state for instance. It is remarkable that this code has been in the 
codebase for 3.5 years and we've not noticed any bug caused by it.

This bug was detected by the work on QPID-3004: The clang++ compiler detected 
that the value being returned by the constructor was not being used at all.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to