Autor: Giuseppe D'Angelo Datum: To: Zoltán Herczeg CC: pcre-dev Betreff: Re: [pcre-dev] PCRE2 and thread safety of jit compilation?
On Mon, Jan 4, 2016 at 8:58 PM, Zoltán Herczeg <hzmester@???> wrote: > Probably a write barrier would make this perfect, but I am not an expert on that, and it requires CPU / OS dependent code.
Heh, it's not a "probably".
Although the pointer assignment itself is likely to be atomic on all
the architectures supported by PCRE, this is not guaranteed unless
you're using atomic types (_Atomic in C11), and especially the release
of the memory _pointed to_ is not atomic. Hence you truly need an
atomic pointer and load acquire / store release semantics (in C11:
atomic_store_explicit(jit_data, memory_order_release) in the thread
creating the JIT data, atomic_load_explicit(jit_data,
memory_order_acquire) in the threads performing atches), otherwise
you're triggering undefined behaviour due to a data race.
(Suppose the thread that performs the jit-study does something like: