-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetAllTokens and ClearDFA sometimes throws NRE in multithread mode #143
Comments
The I believe this is more of a shortcoming in the documentation of a method that is generally discouraged than a bug in the implementation of the method. |
In multithread mode |
@KvanTTT It's not possible to introduce a lock on the hot path in prediction. Doing so would have devastating performance implications for known users running ANTLR 4 in highly concurrent environments. For now I'm documenting that The best way to manage the DFA size in a concurrent environment is to explicitly set the private ATN _currentATN;
public MyLexerFactory()
{
// Initialize _currentATN
ClearDFA();
}
public MyLexer CreateLexer(ICharStream input)
{
MyLexer lexer = new MyLexer(input);
lexer.Interpreter = new LexerATNSimulator(lexer, _currentATN);
return lexer;
}
// Clear the DFA by forcing future instances of MyLexer to be created with a
// different ATN instance, which is initially cleared. Existing instances of
// MyLexer are not affected.
public void ClearDFA()
{
_currentATN = new ATNDeserializer().Deserialize(MyLexer._serializedATN.ToCharArray());
} |
Lexing (and parsing) and cache clearing can not be used simultaniously due to a such multithread issue:
At present time it can be solved with
ReadWriterLockSlim
. See my publication for detail: memory-consumption-of-antlr-runtime.The text was updated successfully, but these errors were encountered: