mike-lischke / antlr4-c3

A grammar agnostic code completion engine for ANTLR4 based parsers
MIT License
396 stars 62 forks source link

Make C++ port thread safe #139

Closed vityaman closed 1 month ago

vityaman commented 1 month ago

It seems to me that the current implementation is not thread safe because of a global variable used in rule processing. As I understand, this std::map is some kind of cache of FollowSetsPerState.

This was one of the reasons for starting work on the C++ port in #132.

std::map is not thread safe, so it should be guarded by some std::mutex or be made thread_local, like DFA cache in ANTLRv4.

It should be noticed that I did these conclusions only by reading the code and did not test it, so the task should be studied firstly.

mike-lischke commented 1 month ago

Correct. Since TypeScript single threaded there's no need to make global variables (caches etc.) thread safe. For languages like Java and C++ this must be added explicitly. The easiest way is probably to use thread_local (C++) or ThreadLocal<>(Java).