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. QSharedMemory: freeze on attach to locked memory.
Forum Updated to NodeBB v4.3 + New Features

QSharedMemory: freeze on attach to locked memory.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k 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.
  • N Offline
    N Offline
    nikitablack
    wrote on last edited by
    #1

    Greetings.

    This code causes a program to hang:
    @QSharedMemory test{"test"};
    test.create(1024); // create and attach
    test.lock(); // lock

    QSharedMemory test2{"test"};
    test2.attach(); // freezes@

    The same happens on detach. Why can this happen - one process can locks a memory, starts to write and throws. Yeah, this is a bad design but it can be. Another process, that knows nothing about the first one trying to attach to memory... and freezes.

    I can't find any way to know that memory is locked. And does that means that attach() works like semaphore, i.e. waits for memory release? Also the same about detach() - should I lock before detaching?

    P.S.: I can't post from chrome or firefox. And there were problems with registering from this browsers. Only IE works for me.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      A bad design is not called bad design just for the sake of the principle but because it causes problems, bugs and errors. Like here.

      lock() and unlock() should be used on a tight bound around writing/reading. Not "globally". And if you throw from within the code surrounded by a lock you should make sure you unlocked it as a cleanup step.

      attach() waits until the shared memory region is unlocked. If you don't unlock it will freeze. You need to fix the locking app.

      You should definitely not lock before detaching. lock/unlock only before/after reading and writing.

      Both Chrome and FF work fine for me. Maybe too eager ad blocking plugin or something?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nikitablack
        wrote on last edited by
        #3

        Yes, you right. I'll review our code. Thank you.

        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