bison-flex-cpp-example icon indicating copy to clipboard operation
bison-flex-cpp-example copied to clipboard

the parser is not reentrant

Open phoenicyan opened this issue 6 years ago • 4 comments

Thank you for publishing this useful example! I compiled and ran it fine using bison 3.0.4 and VS2013. However, as soon as I try to call parser from multiple thread, it crashes. For example: Interpreter i; concurrency::parallel_for(size_t(0), totalCommands, [&](size_t i) { res = i.parse(); } It crashes on this call yystack_[yylen] - index overflow. Is this a reentrancy issue, or I'm missing smth?

phoenicyan avatar Apr 15 '18 23:04 phoenicyan

Bison/flex is not reentrant by default. There is a solution for this problem. I'd be happy to accept a PR.

https://stackoverflow.com/q/32535097/3602072

ezaquarii avatar Apr 16 '18 15:04 ezaquarii

Thank you for the quick reply! I will research this further. It is unfortunate that bison docs and examples are very poor. They attempted to introduce "pure" keyword in 2.7, and then removed support for the keyword in all later releases. All parsers generated by bison that I have seen contain yystack_ which makes them non-reentrant. I'm using workaround: each thread created its own instance of driver/interpreter. Not very efficient but it accomplishes the goal of parallel parsing.

phoenicyan avatar Apr 17 '18 05:04 phoenicyan

I'd be happy to include it if you don't mind. That example could be handy.

ezaquarii avatar Apr 17 '18 08:04 ezaquarii

Thank you for the quick reply! I will research this further. It is unfortunate that bison docs and examples are very poor. They attempted to introduce "pure" keyword in 2.7, and then removed support for the keyword in all later releases. All parsers generated by bison that I have seen contain yystack_ which makes them non-reentrant. I'm using workaround: each thread created its own instance of driver/interpreter. Not very efficient but it accomplishes the goal of parallel parsing.

phoenicyan avatar Apr 27 '18 03:04 phoenicyan