Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMutex pointer is misaligned
Forum Updated to NodeBB v4.3 + New Features

QMutex pointer is misaligned

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 10.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goocreations
    wrote on last edited by
    #1

    I have a centralized buffer class which is being read and written to from a number of different threads. A simple version of my buffer class looks as follows:

    @MyBuffer
    {
    public:

    void function1()
    {
    QMutexLocker locker(&mMutex);
    // Do some stuff
    }

    int size()
    {
    QMutexLocker locker(&mMutex); // Error here
    return mData->size();
    }

    private:
    mutable QMutex mMutex;
    QByteArray mData;
    }@

    Everything works fine, except that I always get the following error:

    @ASSERT failure in QMutexLocker: "QMutex pointer is misaligned", file /usr/local/Qt-5.0.0/include/QtCore/qmutex.h, line 117@

    on the line marked with “// Error here” in the code above.
    What is happening here? How can I fix it?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      broadpeak
      wrote on last edited by
      #2

      See the last reply in this thread:
      http://stackoverflow.com/questions/9458664/qthread-assert-failure-in-qmutexlocker-qmutex-pointer-is-misaligned
      Maybe helps...

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goocreations
        wrote on last edited by
        #3

        Yip, read that post before. The problem is I have a very large system. I know systems should be leak-free, but it is near impossible to find all memory leaks in the system I'm working on. Isn't there any way I can track the problem more closely?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          [quote author="goocreations" date="1349793115"]Yip, read that post before. The problem is I have a very large system. I know systems should be leak-free, but it is near impossible to find all memory leaks in the system I'm working on. Isn't there any way I can track the problem more closely?[/quote]

          You can try with gprof or valgrind.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goocreations
            wrote on last edited by
            #5

            So this is the only reason why this failure occurs?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goocreations
              wrote on last edited by
              #6

              I've now written my own Mutex and MutexLocker classes based on pthread (pthread_mutex_t) and I'm not getting any kind of locking problems. So why is this such an issue with QMutex?

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

                You've corrupted your object and the QMutex member has become invalid. Review your code or valgrind it.

                Your own mutex implementation just removes the assertion, but does not change the fact that your code is most probably broken.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goocreations
                  wrote on last edited by
                  #8

                  Lukas, what do you mean by "corrupted your object"? Is that the object where I lock the mutex, or is it the mutex object itself?

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lgeyer
                    wrote on last edited by
                    #9

                    You've written to a memory region you are not allowed to, most probably due to a buffer underrun or a dangling pointer, which leads to a corrupted MyBuffer and in further consequence QMutex object.

                    It should be actually quite easy to visualize. Place a breakpoint at the QMutexLocker constructor. If the address for <code>&mMutex</code> varies between consecutive calls you've corrupted your memory somewhere.

                    You might be able to trace the problem with some properly placed data breakpoints (for example on <code>*this</code>) or, as mentioned, valgrind it.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved