Correct information about multi-threaded compilation.

This commit is contained in:
Philip.Hazel 2016-02-25 17:40:16 +00:00
parent 80d7d825e1
commit 6a3b36fa15
1 changed files with 10 additions and 22 deletions

View File

@ -1,4 +1,4 @@
.TH PCRE2API 3 "06 February 2016" "PCRE2 10.22" .TH PCRE2API 3 "25 February 2016" "PCRE2 10.22"
.SH NAME .SH NAME
PCRE2 - Perl-compatible regular expressions (revised API) PCRE2 - Perl-compatible regular expressions (revised API)
.sp .sp
@ -488,37 +488,25 @@ documentation for more details.
.P .P
In a more complicated situation, where patterns are compiled only when they are In a more complicated situation, where patterns are compiled only when they are
first needed, but are still shared between threads, pointers to compiled first needed, but are still shared between threads, pointers to compiled
patterns must be protected from simultaneous access by multiple threads, at patterns must be protected from simultaneous writing by multiple threads, at
least until a pattern has been compiled. The logic can be something like this: least until a pattern has been compiled. The logic can be something like this:
.sp .sp
Get a read-only (shared) lock (mutex) for pointer
if (pointer == NULL) if (pointer == NULL)
{ {
Get exclusive access to pointer Get a write (unique) lock for pointer
if (pointer == NULL) pointer = pcre2_compile(... pointer = pcre2_compile(...
Release exclusive access to pointer
} }
Release the lock
Use pointer in pcre2_match() Use pointer in pcre2_match()
.sp .sp
Of course, testing for compilation errors should also be included in the code. Of course, testing for compilation errors should also be included in the code.
.P .P
If JIT is being used, but the JIT compilation is not being done immediately, If JIT is being used, but the JIT compilation is not being done immediately,
(perhaps waiting to see if the pattern is used often enough) similar logic is (perhaps waiting to see if the pattern is used often enough) similar logic is
required. The PCRE2_INFO_JITSIZE information call can detect whether there has required. JIT compilation updates a pointer within the compiled code block, so
been a successful call to \fBpcre2_jit_compile()\fP, but there is no way to a thread must gain unique write access to the pointer before calling
tell whether JIT has been called and failed (a very few pattern features are \fBpcre2_jit_compile()\fP.
not supported by JIT). Therefore, a separate flag is needed:
.sp
if (!jit_tried)
{
Get exclusive access to jit_tried
(if !jit_tried) pcre2_jit_compile(pointer, ...
jit_tried = TRUE
Release exclusive access to jit_tried
}
Use pointer in pcre2_match()
.sp
Other threads can use pointer for non-JIT matching while JIT compilation is in
progress.
. .
. .
.SS "Context blocks" .SS "Context blocks"
@ -3221,6 +3209,6 @@ Cambridge, England.
.rs .rs
.sp .sp
.nf .nf
Last updated: 06 February 2016 Last updated: 25 February 2016
Copyright (c) 1997-2016 University of Cambridge. Copyright (c) 1997-2016 University of Cambridge.
.fi .fi