Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-10364

QSharedMemory lock doesn't work as documented

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • Some future release
    • 4.5.2, 4.6.2, 5.0.2
    • Core: Threads
    • None

    Description

      UI tseems to me the lock in QSharedMemory doesn't work as advertised. It's very easy to have two processes lock the same segment simultaneously. The problem is the underlying QSystemSemaphore, which reinitialize the semaphore each time a process try to access the segment. If a process cause initialization of the semaphore while another has the lock, the lock is broken.

      The attached program is an example. Just launch two copies in two terminals on the same linux host.

      What works:
      1) in the first copie, do control-D twice to display "before lock"
      2) in the second copie, do the same
      3) in the first, hit control-D again, it goes to "after lock"
      4) in the second, hut contro-D again, nothing seems to happen
      5) in the first, another ^D ; it goes to "after unlock", while the second copie goes to "after lock"

      -> the lock worked.

      What doesn't work:
      1) in the first copie, do control-D thrice to display "after lock"
      2) in the second copie, hit control-D thrice... and it does display "after lock" too !

      -> the lock didn't work

      This is probably not easy to fix, because AFAIK there is no way to tell whether a pre-existing semaphore is valid or not.

      At the very least, this should be documented to avoid falling into this trap.

      A possibility would be a parameter to QSharedMemory to "open" the semaphore instead of "creating" it, but an automatic solution would be better.

      Attachments

        1. main.cpp
          0.6 kB
        2. test3.cc
          1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            dolbeau Romain Dolbeau
            Votes:
            8 Vote for this issue
            Watchers:
            14 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes