[thiago at kde.org: Re: Multiple QRegExp crashes when multithreading in KRunner]

Milian Wolff mail at milianw.de
Fri Jan 14 09:54:41 UTC 2011


On 01/14/11 09:36, Aleix Pol wrote:
> On Fri, Jan 14, 2011 at 9:00 AM, Andreas Pakulat <apaku at gmx.de
> <mailto:apaku at gmx.de>> wrote:
>
>     Hi,
>
>     see below, its a much more elegant solution than using a mutex and
>     possibly faster too. So maybe we can use this to get rid of the mutex in
>     the cmake manager for the regexp's its using?
>
>     Andreas
>
>     ----- Forwarded message from Thiago Macieira <thiago at kde.org
>     <mailto:thiago at kde.org>> -----
>
>     Date: Fri, 14 Jan 2011 01:17:24 +0100
>     From: Thiago Macieira <thiago at kde.org <mailto:thiago at kde.org>>
>     To: kde-core-devel at kde.org <mailto:kde-core-devel at kde.org>
>     Subject: Re: Multiple QRegExp crashes when multithreading in KRunner
>     User-Agent: KMail/4.6 beta3 (Linux/2.6.35.6-desktop-1mnb;
>     KDE/4.5.86; i686;
>             git-3cbb929; 2010-12-23)
>
>     On Thursday, 13 de January de 2011 23:33:14 Milian Wolff wrote:
>      > Matthias Fuchs, 13.01.2011:
>      > > Hi,
>      > >
>      > > There are some crashes related to QRegExp and multithreading,
>     so they
>      > > appear when using KRunner.
>      >
>      > QRegExp is not threadsafe, you either have to guard it with a
>     mutex or make
>      > sure it's not shared between threads.
>
>     You're right.
>
>     To be clear: as per Qt terminology, QRegExp is reentrant, not
>     thread-safe.
>
>     That means you can use QRegExp in different threads, at the same
>     time, provided
>     that they point to different objects. If it's the same object, do as
>     Milian
>     said.
>
>     It's easier to just create a copy in this case.
>     --
>     Thiago Macieira - thiago (AT) macieira.info <http://macieira.info> -
>     thiago (AT) kde.org <http://kde.org>
>       Senior Product Manager - Nokia, Qt Development Frameworks
>           PGP/GPG: 0x6EF45358; fingerprint:
>           E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>
>
>
>     ----- End forwarded message -----
>
>     --
>     Future looks spotty.  You will spill soup in late evening.
>
>     --
>     KDevelop-devel mailing list
>     KDevelop-devel at kdevelop.org <mailto:KDevelop-devel at kdevelop.org>
>     https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel
>
>
> Milian got rid of it already, IIRC, he changed it to regular code and it
> was still fine :P.
>
> I don't see what's the better solution, though..

The better solution would be to copy the static regexp data into a local 
variable. It might indeed be faster than a mutex thingy, and definitely 
faster than creating the regexp from a string representation all the 
time. Anyways, for CMake I removed the usage of QRegExp in that one 
position alltogether and replaced it with simple QString operations. 
This is faster than all of this ;-) There might be more cases where we 
use QRegExp though, and we should benchmark this and see wether it's 
worth it.

bye

-- 
Milian Wolff
http://milianw.de




More information about the KDevelop-devel mailing list