Results 1 to 5 of 5

Thread: QSharedMemory and QThreads

  1. #1

    Default QSharedMemory and QThreads

    Goodmorning everyone,

    I'm developing a multithreaded application that uses a class that inherits from QSharedMemory.

    Since some time ago I was using classes that extended QThread that opens (creates if it hasn't been created or attaches in the other case) the shared memory object in the constructor and close it in the destructor.
    I had sometimes problems when destroying the threads so I decided to switch to the moveToThread suggested approach. Using this last, it seems that I've get rid of the old problems but I've got new ones..

    I'm using the deleteLater approach and now sometimes I get this error: "unable to set key on lock" in my constructor and other times, in the destructor it remains blocked on the detach. I read the QSharedMemory code ,including the Linux part (that I'm using), in order to understand how it works. It seems that it uses locks in the attach and detach so it seems like a deadlock problem.

    Does anyone know what that error mean?



    Cheers!

  2. #2
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSharedMemory and QThreads

    Looks like it could be 1 of a few things. I think you'll have to look at the actual error code to get a more specific idea on what is going wrong.
    Qt Code:
    1. bool QSharedMemoryPrivate::initKey()
    2. {
    3. if (!cleanHandle())
    4. return false;
    5. #ifndef QT_NO_SYSTEMSEMAPHORE
    6. systemSemaphore.setKey(QString(), 1);
    7. systemSemaphore.setKey(key, 1);
    8. if (systemSemaphore.error() != QSystemSemaphore::NoError) {
    9. QString function = QLatin1String("QSharedMemoryPrivate::initKey");
    10. errorString = QSharedMemory::tr("%1: unable to set key on lock").arg(function);
    11. switch(systemSemaphore.error()) {
    12. case QSystemSemaphore::PermissionDenied:
    13. error = QSharedMemory::PermissionDenied;
    14. break;
    15. case QSystemSemaphore::KeyError:
    16. error = QSharedMemory::KeyError;
    17. break;
    18. case QSystemSemaphore::AlreadyExists:
    19. error = QSharedMemory::AlreadyExists;
    20. break;
    21. case QSystemSemaphore::NotFound:
    22. error = QSharedMemory::NotFound;
    23. break;
    24. case QSystemSemaphore::OutOfResources:
    25. error = QSharedMemory::OutOfResources;
    26. break;
    27. case QSystemSemaphore::UnknownError:
    28. default:
    29. error = QSharedMemory::UnknownError;
    30. break;
    31. }
    32. return false;
    33. }
    34. #endif
    35. errorString = QString();
    36. error = QSharedMemory::NoError;
    37. return true;
    38. }
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: QSharedMemory and QThreads

    Hi there,

    yep I saw that code but in order to get the specific error code I need to do some changes. I guess I'll try to get it.


    The specifi message error I get is: "QSharedMemoryPrivate::initKey: unable to set key on lock"

  4. #4

    Default Re: QSharedMemory and QThreads

    The error code is: QSharedMemory::KeyError 3 The operation failed because of an invalid key.


    I'm wondering what can it be.. the key is the same in all the threads but it should work in this way

  5. #5
    Join Date
    Oct 2015
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSharedMemory and QThreads

    Hi, I'am Djon. Sorry for bad english, i'am from Russia.

    The problem is that the list is full of stored keys. This error occurs when you have created a large number of copies QHaredMemory members with keys.
    Last edited by Djoni_D; 9th October 2015 at 14:17.

Similar Threads

  1. QSharedMemory example
    By weixj2003ld in forum Qt Programming
    Replies: 3
    Last Post: 9th October 2015, 13:14
  2. QSharedMemory
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2011, 12:49
  3. about the QSharedMemory
    By banban0802 in forum Qt Programming
    Replies: 5
    Last Post: 10th August 2010, 13:08
  4. new vs QSharedMemory
    By JovianGhost in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2010, 01:34
  5. Qthreads
    By Sheetal in forum Qt Programming
    Replies: 5
    Last Post: 23rd March 2007, 12:12

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.