Author: Giuseppe D'Angelo Date: To: Pcre Subject: [pcre-dev] PCRE2 and thread safety of jit compilation?
Howdy,
In PCRE1, one could have multiple threads matching at the same time
using the same compiled pattern. One (or more) of the threads could
have /also/ studied and jit-compiled the pattern, without interfering
with the other threads, by creating and operating on the extra "study
data" object. After that, the thread could have also gave the pointer
to the study data to the other threads, which then could benefit from
the study results.
In PCRE2 the extra studying APIs / study data parameter were removed.
(Apparently studying is cheap enough that it's always done during
pattern compilation.)
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?