Is Perl Parse :: RecDescent Stream Safe?

I have a web application that uses a parser created using Parse :: RecDescent. A parser object is needed in several parts of the application, and since the parser takes up quite a bit of memory, I still considered the parser object as a singleton. This works well in a clean CGI environment, since only one expression is parsed by the same object at a time. However, I'm not sure if this will work when working in an environment where the same site parser parses more than one line at a time.

For example, if I try to run an application in FastCGI, can this be a problem if two queries simultaneously use the same parser to parse different lines?

If I need so that I can change the application so that the parser is no longer a single, however, I would prefer not so that the current solution is simpler.

+3
source share
1 answer

As far as I know, FastCGI does not use Perl threads, but processes. Therefore, you must be safe.

Also, if you use Perl and Parse :: RecDescent streams, you will probably never use the same object to analyze different things at the same time. Pseudocode:

use threads;
use Parse::RecDescent;
our $SingletonRD = Parse::RecDescent->new($grammar);

my @threads = map {threads->new(\&thread_loop)} (1..5);

sub thread_loop {
    $SingletonRD->parse($text);
}

This is an example where threads are created after a singleton. Here's what happens:

  • You create a single object and save it to $SingletonRD.
  • You create (in a loop) five threads. When spawns a new thread, perl does
    • . .
    • perl- ( OP).

$SingletonRD . . , , , -.

threads:: shared . () . , , Parse:: RecDescent.

PS: Parse:: Yapp , Parse:: Eyapp. , (), Parse:: RecDescent, , .

+4

Source: https://habr.com/ru/post/1731203/


All Articles