Results 1 to 17 of 17

Thread: Interprocess nonblocking semaphore / mutex / shared memory.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Interprocess nonblocking semaphore / mutex / shared memory.

    Sorry read to fast.
    But you can do it your self.
    For example, you can override QSharedMemory so:
    Qt Code:
    1. // in the header:
    2. bool m_bLocked;
    3.  
    4. //and
    5. bool isLocked() {return m_bLocked; }
    6.  
    7.  
    8. //in the implementation:
    9. //initialize in the ctor
    10.  
    11. bool MyQSharedMemory::tryLock()
    12. {
    13. if(!m_bLocked){
    14. m_bLocked = QSharedMemory::lock();
    15. return m_bLocked;
    16. }
    17.  
    18. return false;
    19. }
    To copy to clipboard, switch view to plain text mode 

    But I would go through the QSharedMemory doc thoroughly, as my guess is that the trolls didn't build it in in the first place because probably it conflicts with the way QSharedMemory work, and the way it should be used.
    Since I didn't work with it yet, I can't say.

    Another way is to use to protect the resource with a mutex, and only do something with it if you managed to lock the mutex.
    Qt Code:
    1. if(mutex.tryLock()){
    2. //Do something with resource
    3. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 11th May 2011 at 09:33.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. shared memory wont attach
    By daemonna in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2010, 01:11
  2. Does Qt support shared memory ?
    By Shawn in forum Qt Programming
    Replies: 11
    Last Post: 3rd November 2009, 17:07
  3. QT shared memory
    By sweetsubha2020 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2009, 05:30
  4. MySQL and shared-memory connection
    By patrikd in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2008, 16:53
  5. How to clear shared memory?
    By THRESHE in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2008, 18:28

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.