parse: fix data race initializing lexer::atwords parse_all() runs parser/lexer constructors concurrently, and the lexer's first-run population of the process-global atwords set was guarded only by an atwords.empty() check. Concurrent inserts corrupted the unordered_set and, with libc++, crashed stap in pass 2 about a quarter of the time. Use call_once for the one-time population. Co-authored-by: OpenCode agent <noreply@opencode.ai>
diff --git a/parse.cxx b/parse.cxx index 1d850b4..389900a 100644 --- a/parse.cxx +++ b/parse.cxx
@@ -1491,8 +1491,10 @@ keywords.insert("catch"); } - if (atwords.empty()) - { + // NB: atwords is process-global, and lexer constructors may run + // concurrently (parse_all), so guard the one-time population. + static once_flag atwords_once; + call_once (atwords_once, [&]() { // NB: adding new @words is mildly disruptive to existing // scripts that define macros with the same name, but not // really. The user will merely receive a warning that they are @@ -1529,7 +1531,7 @@ atwords.insert("enum"); if (has_version("5.6")) atwords.insert("enumname"); - } + }); } unordered_set<string> lexer::atwords;