Re: [pcre-dev] PCRE2 and thread safety of jit compilation?

Startseite
Nachricht löschen
Autor: ph10
Datum:  
To: Giuseppe D'Angelo
CC: Pcre
Betreff: Re: [pcre-dev] PCRE2 and thread safety of jit compilation?
On Sun, 3 Jan 2016, Giuseppe D'Angelo wrote:

> In PCRE2 the extra studying APIs / study data parameter were removed.
> (Apparently studying is cheap enough that it's always done during
> pattern compilation.)


Yes, it seemed like a good idea to remove the (apparently) unnecessary
complication, and always gain the performance advantage.

> Now the optional study step is only done when JIT compiling a pattern
> through pcre2_jit_compile, which operates on the very same pcre2_code
> object returned by pcre2_compile.
>
> However, this opens a question about the thread safety of this
> operation. Say we have the scenario depicted above -- two threads both
> matching using the same compiled pattern, but one thread decides to
> also jit-compile the pattern. Is this combination threadsafe? If not,
> are there any recommended workarounds?


We need Zoltán to answer this in detail, but looking at the code makes
me think this is not thread-safe. It's not a scenario that had occurred
to me.

If there is no other workaround, I suppose the only thing to do is to
have some kind of lock that stops other threads from calling
pcre2_match() while one of them is running pcre2_jit_compile() for the
same compiled pattern. This does not sound very satisfactory.

I have made a note to update the documentation to cover this situation,
once we have got clarification (and decided whether or not to change
anything).

Philip

--
Philip Hazel