[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Deprecation of QSharedMemory and QSystemSemaphore
From:       Méven <meven29 () gmail ! com>
Date:       2023-12-01 16:19:43
Message-ID: CAOvFf8PWqE00+OMbyGPoiFH3FyOb=jWbseHt_L4Cp3TC=CTdKQ () mail ! gmail ! com
[Download RAW message or body]

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@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

[Attachment #3 (text/html)]

<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-fi \
les">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 &lt;<a \
href="mailto:thiago@kde.org">thiago@kde.org</a>&gt; 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> &gt; QSystemSemaphore:<br>
&gt; * Solid optical disc handling<br>
&gt; * Digikam server starter<br>
&gt; <br>
&gt; QSharedMemory:<br>
&gt; * Marble<br>
&gt; * KMemFile used by KSycoca<br>
&gt; * Solid again<br>
&gt; * Snorenotify<br>
&gt; * Amarok<br>
&gt; * Kdenlive<br>
&gt; <br>
&gt; At a glance it looks like some (e.g. Solid) can probably use QLockFile<br>
&gt; or are Linux-specific and can use memfd<br>
&gt; <br>
&gt; Qt folks are aware of QtSingleApplication but we couldn't really speak<br>
&gt; 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&#39;re using QSharedMemory for (how \
<br> many processes, what&#39;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>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic