Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-18356

Example in QMutexLocker Documentation is misleading

    XMLWordPrintable

    Details

      Description

      In the QMutexLocker documentation the before and after example code would run with a significant difference. The version that directly locks QMutex unlocks BEFORE running moreComplexFunction(), but when using QMutexLocker the lock would be held during that function call. The QMutex version:

      mutex.lock();

      int retVal = 0;

      switch {
      case 0:
      case 1:
      mutex.unlock();
      return moreComplexFunction;

      vs. the QMutexLocker version:

      QMutexLocker locker(&mutex);

      int retVal = 0;

      switch {
      case 0:
      case 1:
      return moreComplexFunction;

      Since this relies on the C++ compiler to handle scoping to test this I wrote and ran:

      #include <stdio.h>

      class dummy
      {
      public:
      dummy()

      Unknown macro: { printf("creating dummyn"); }

      ~dummy()

      Unknown macro: { printf("deleting dummyn"); }

      };

      int callMe()
      {
      printf("called callMe\n");
      return 42;
      }

      int main(int argc, char **argv)
      {
      dummy a;
      return callMe();
      }

      The output was as expected:

      [jdunn@temp QtOpenCV]$ ./test
      creating dummy
      called callMe
      deleting dummy

      Also, your bug reporting interface doesn't appear to support a tag to quote code well.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            teemukat Teemu Katajisto (Inactive)
            Reporter:
            jdunn14 Joseph Dunn
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes