Is Perl's Parse::RecDescent thread safe? -


I have a web application that uses a parser built with Pars :: Rick Denissent. In many parts of the application a parser object is required and because the parser takes very little memory, now I need to treat parsing objects as a singleton. It works well in a pure CGI environment because only one expression is parsed in the same object at the same time. I am however unsure if this will still work while moving in an environment where the same object parser is parsing more than one string.

For example, if I can try to run the application under FastCGI, then this can be a problem if two requests at the same time to parse the same parser object into different strings Use?

If I want to change the application then the parser will no longer be singleton, although I prefer the current solution is not straightforward.

For my best knowledge, Pearl threads do not use FastCGI but processes like this Must be safe.

In addition, if you are using Pearl threads and pars :: Rick Dentant, you never to parse the same objects equally concurrently > Are. Pseudocode:

  Use threads; Use Parse :: RecDescent; Our $ Singleton RD = Pars :: Recessent-> New ($ grammar); My @ Threads = Map {Thread-> New (\ & amp; Thread_Loop)} (1..5); Sub thread_lop {$ singleton RD-> purse ($ text); }  

This is an example where the formula is created after singletons. Here's what:

  • You create a single object and store it in $ Singleton RD .
  • You (in a loop) make five threads. When a new thread is created, Perl creates a copy of the
    • global symbol table. It includes all package variables and sub-routines.
    • Make a copy of various Pearl-Interpreter internal data structures (excluding OP trees).

This effectively clones $ Singleton RD for each thread, no memory saved Now, if you If you want to set the parser only after creating a thread, the variable between them will not be shared, so saving any memory and is not a thread-unsupported here.

In theory, you can use thread :: to share data between sources. But these objects and complex nested structures (easily) do not work. Therefore, it will probably be out of the question for Parse :: RecDescent Parser.

PS: Parse :: Yapp or better yet parsed: Take a look at Eyapp. They parse: Rick is much more algorithmic than Dennis, and I think they are likely to use less memory.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -