<div dir="ltr"><div>I thought about using QSharedMemory in previewjob / thumbnail ioworker to allow shared memory across OS aka better thumbnails on windows.</div><div><br></div><div>Answers in the mail show the alternative but will require a bunch of tinkering.<br></div><div><pre>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. See
<a href="https://doc.qt.io/qt-6/shared-memory.html#sharing-memory-via-memory-mapped-files">https://doc.qt.io/qt-6/shared-memory.html#sharing-memory-via-memory-mapped-files</a>
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.</pre></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 1 déc. 2023 à 15:50, Thiago Macieira <<a href="mailto:thiago@kde.org">thiago@kde.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Friday, 1 December 2023 14:01:14 CET Kai Uwe Broulik wrote:<br>
> QSystemSemaphore:<br>
> * Solid optical disc handling<br>
> * Digikam server starter<br>
> <br>
> QSharedMemory:<br>
> * Marble<br>
> * KMemFile used by KSycoca<br>
> * Solid again<br>
> * Snorenotify<br>
> * Amarok<br>
> * Kdenlive<br>
> <br>
> At a glance it looks like some (e.g. Solid) can probably use QLockFile<br>
> or are Linux-specific and can use memfd<br>
> <br>
> Qt folks are aware of QtSingleApplication but we couldn’t really speak<br>
> of the other use cases, in particular KSycoca.<br>
<br>
KSycoca is supposed to be real sharing of memory.<br>
<br>
For the other ones, the question is what they're using QSharedMemory for (how <br>
many processes, what's the ownership model).<br>
<br>
-- <br>
Thiago Macieira - thiago (AT) <a href="http://macieira.info" rel="noreferrer" target="_blank">macieira.info</a> - thiago (AT) <a href="http://kde.org" rel="noreferrer" target="_blank">kde.org</a><br>
Software Architect - Intel DCAI Cloud Engineering<br>
<br>
<br>
<br>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Méven</div>