Deprecation of QSharedMemory and QSystemSemaphore

Méven meven29 at gmail.com
Fri Dec 1 16:19:43 GMT 2023


I thought about using QSharedMemory in previewjob / thumbnail ioworker to
allow shared memory across OS aka better thumbnails on windows.

Answers in the mail show the alternative but will require a bunch of
tinkering.

Q: I still need shared memory, what can I use instead?
A: Use QFile::map(). A memory-mapped file without the QFile::MapPrivateOption
is shared memory.
Seehttps://doc.qt.io/qt-6/shared-memory.html#sharing-memory-via-memory-mapped-files

Files are well-understood and common across all OSes, which should also make
reviewing code for problems and race conditions much simpler.

For example, using QTemporaryFile and renaming, you can prepare the shared
memory area before committing it to visibility to other processes.


Q: I need an equivalent of QSystemSemaphore, what can I use instead?
A: Use QFile::map() and put an atomic or a PThread locking primitive there.
Alternatively, use QLockFile.



Le ven. 1 déc. 2023 à 15:50, Thiago Macieira <thiago at kde.org> a écrit :

> On Friday, 1 December 2023 14:01:14 CET Kai Uwe Broulik wrote:
> > QSystemSemaphore:
> > * Solid optical disc handling
> > * Digikam server starter
> >
> > QSharedMemory:
> > * Marble
> > * KMemFile used by KSycoca
> > * Solid again
> > * Snorenotify
> > * Amarok
> > * Kdenlive
> >
> > At a glance it looks like some (e.g. Solid) can probably use QLockFile
> > or are Linux-specific and can use memfd
> >
> > Qt folks are aware of QtSingleApplication but we couldn’t really speak
> > of the other use cases, in particular KSycoca.
>
> KSycoca is supposed to be real sharing of memory.
>
> For the other ones, the question is what they're using QSharedMemory for
> (how
> many processes, what's the ownership model).
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>    Software Architect - Intel DCAI Cloud Engineering
>
>
>
>

-- 
Méven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-devel/attachments/20231201/1a5a725e/attachment-0001.htm>


More information about the kde-devel mailing list