Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
4.5.2, 4.6.2, 5.0.2
-
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.