Results 1 to 4 of 4

Thread: QT 4.7.4 vs QT4.8.4 QMutexLocker works one machine not another vice versa

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT 4.7.4 vs QT4.8.4 QMutexLocker works one machine not another vice versa

    The QMutex you are using with QMutexLocker, which mode is it in. Is in QMutex::Recursive or QMutex::NonRecursive mode? Also can you elaborate whether the function is not a recursive calling function?
    Also do you get an message with assert failure like this:
    ASSERT failure in QMutexLocker: "QMutex pointer is misaligned"

  2. #2
    Join Date
    Dec 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT 4.7.4 vs QT4.8.4 QMutexLocker works one machine not another vice versa

    The function is not recursive, and can only run in release mode on these machines, but do not get the ASSERT message. Below is sample of how I am using the mutex.
    // .h file snippet

    private:
    QMutex outReqsMutex_;
    // other defines below
    ------------------------------
    // .cpp file snippet below

    int client::getStatus()
    {
    QUrl url = buildUrl("/pxs/status");
    QMutexLocker ml(&outReqsMutex_);

    // Is there an outstanding request for this URL?
    if (outstandingRequests_.contains(serverHost, url)) {
    return 0;
    }

    // send the request below
    // Add the URL to the outstanding set.
    outstandingRequests_.insert(serverHost, url);

    QNetworkReply *nr = NULL;
    QNetworkRequest netReq(url);
    netReq.setHeader(QNetworkRequest::ContentTypeHeade r, CPS_MIME_TYPE_TEXTPLAIN_UTF8);
    nr = networkManager.get(netReq);
    replyQueue_.insert(nr, QDateTime::currentDateTime());
    return 1;
    }

    /////////
    // within the network request finish slot I lock and remove from the map
    {
    QMutexLocker ml(&outReqsMutex_);
    int nnum = replyQueue_.remove(reply);
    outstandingRequests_.remove(reply->url().host(), reply->url());
    }

    thanks.

  3. #3
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT 4.7.4 vs QT4.8.4 QMutexLocker works one machine not another vice versa

    Two functions share a mutex. So if funcA while running on ThreadA calls funcB, it tries to regain a non-recursive lock.
    as you know a single mutex should only ever be acquired once by a single thread within the same call chain. Attempting to acquire (or hold) the same mutex twice, within the same thread context, should be considered an invalid scenario, and should be handled appropriately (usually via an ASSERT as you are breaking a fundamental contract of your code).
    So you need to make sure that (a) your mutex is non-recursive. (b) functions with the lock are exclusive.

    And if the network request finish slot is only used as a slot, and not called as a function anywhere else... we may be sure that the function will be executed only on the thread the class resides...

Similar Threads

  1. kde pid from window id and vice versa
    By sky in forum KDE Forum
    Replies: 2
    Last Post: 18th May 2013, 09:17
  2. Qstring to Qdate and vice versa
    By sai_3289 in forum Qt Programming
    Replies: 10
    Last Post: 12th February 2013, 11:54
  3. Replies: 3
    Last Post: 13th May 2011, 13:46
  4. Replies: 10
    Last Post: 15th March 2011, 14:14
  5. conversion between string to hex and vice versa
    By mohanakrishnan in forum Newbie
    Replies: 2
    Last Post: 5th December 2009, 11:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.