-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make staticData variable threadsafe
I've hit a bug developing a go parser and running multiple instances of it with t.Parallel() Turned out that staticData var was a global and would throw concurrent data access errors when running the test suite with -race This commit fixes it by doing the following: 1. turn <parser.grammarName; format="cap">ParserStaticData into a struct 2. Teach <parser.name; format="cap">Init() to return a pointer to new instance of this struct 3. Teach <parser.name; format="cap">Init() to initialize it upon construction 4. Teach the parser constructor to use its own value for this var rather than a global I took similar steps for the Lexer I've been able to run 10000 concurrent parsers in this setup without having any performance/memory usage problems Signed-off-by: Tomasz Nguyen <[email protected]> Signed-off-by: Tomasz Nguyen <[email protected]>
- Loading branch information
Showing
1 changed file
with
18 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters