Autor: Zoltán Herczeg Data: Para: Matthew Hall CC: pcre-dev Asunto: Re: [pcre-dev] Using pcre_assign_jit_stack and pcre_extra* in
multiple threads
Hi Matthew,
>I have a question about the internal thread JIT stack accessed by using
>pcre_assign_jit_stack(re_extra, NULL, NULL) .
The internal thread stack is actually the real thread stack. In jit_machine_stack_exec(), it is simply declared as a local variable:
pcre_uint8 local_space[MACHINE_STACK_SIZE];
This is the most portable way to access something thread specific, since every thread has (must have) its own stack space.
>In my program I have a linked list of pcre* and pcre_extra* entries which are
>created at program start, then iterated over by multiple threads.
>
>Each thread would call pcre_assign_jit_stack before matching using the pcre*
>and pcre_extra* as arguments to pcre_exec.
The NULL, NULL option is also the default, so you don't need to call it from each thread.
>However I'm unclear on one thing. If each thread calls pcre_assign_jit_stack
>on the same pcre* at the same time, will any of the entries in the pcre_extra*
>end up in an indeterminate state, because they're referencing the jit_stack,
>or is it setup so that the jit_stack only references the pcre_extra and not
>the other way around?
Exactly this could be the problem, if you call pcre_assign_jit_stack from multiple threads, since pcre_extra has a reference to the jit_stack. Instead, it is recommended to call it only at initialization time, and pass a function rather than a stack instance for those patterns, which are used from multiple threads. The passed function will be called before each pcre_(jit)_exec, and it can return a stack assigned for each thread. But if the 32K stack space is enough, you don't need to do anything (don't call pcre_assign_jit_stack at all).