[Interest] Problem with QSharedMemory

Thiago Macieira thiago.macieira at intel.com
Sat Jan 26 18:58:35 CET 2013


On sábado, 26 de janeiro de 2013 11.38.58, Guido Seifert wrote:
> The program runs for hrs and the code seems to be ok. Most of the time. But
> in my logs I see, that from time to time I get an error. The shared memory
> cannot be created, because it already exists. I can live with it, but it
> looks unclean to me. Could it be that there exists a race condition between
> the last detach() and a create()? 

Yes. The QSharedMemory code is really racy. If you attach and detach, create 
and attempt to destroy, it's quite easy to get the QSharedMemory code to fail.

See 
http://qt.gitorious.org/qt/qtbase/commit/60fc88a09c0127bf79563e5449e049f3c9e0fc55

You'll note two things:
 1) the race condition begins with QSystemSemaphore
 2) the commit doesn't fix the race condition, it only works around it
 3) the code was actually entering into a deadlock

Unfortunately, I don't know how to fix the problem. I'd probably have to 
rewrite both classes with different semantics to make it work.

> Maybe it would be nice to have a signal, which tells, when a segment really
> is destroyed? OR course, if such a signal is even possible.

Since any segment can be recreated, it's not easy to do that.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130126/5b4b4197/attachment.sig>


More information about the Interest mailing list