Results 1 to 12 of 12

Thread: local static QMutex

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows
    Thanks
    17
    Thanked 27 Times in 24 Posts

    Default local static QMutex

    Hello, could somebody answer me if it is safe to use static QMutex on the stack of the function that is called by several threads (see the same code below). Static variables are created only once, but I'm afraid, perhaps, another thread may try to use it when it is not yet created.

    Qt Code:
    1. // safe or not?
    2. void testFunc()
    3. {
    4. static QMutex mutex;
    5. mutex.lock();
    6. // access shared resource
    7. mutex.unlock();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mentalmushroom; 23rd January 2012 at 17:43. Reason: incorrect question

Similar Threads

  1. static QMutex
    By mhoover in forum Qt Programming
    Replies: 7
    Last Post: 8th August 2014, 05:39
  2. QMutex QMutex::Recursive is not a type name
    By Qiieha in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2011, 14:01
  3. Using a QMutex as a static class member
    By emostar in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2009, 13:48
  4. QMutex
    By weixj2003ld in forum Qt Programming
    Replies: 6
    Last Post: 14th April 2009, 22:32
  5. New to QMutex
    By durbrak in forum Qt Programming
    Replies: 3
    Last Post: 12th March 2009, 21:16

Tags for this Thread

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.