-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Avoid a race condition in opt-viewer/optrecord #131214
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,17 +64,19 @@ class Remark(yaml.YAMLObject): | |
|
||
default_demangler = "c++filt -n" | ||
demangler_proc = None | ||
demangler_lock = Lock() | ||
|
||
@classmethod | ||
def set_demangler(cls, demangler): | ||
cls.demangler_proc = subprocess.Popen( | ||
demangler.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE | ||
) | ||
cls.demangler_lock = Lock() | ||
|
||
@classmethod | ||
def demangle(cls, name): | ||
with cls.demangler_lock: | ||
if not cls.demangler_proc: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this really need to be within the Lock? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the underlying problem is that before that patch, caller had to ensure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When it's outside of the lock, two workers could attempt to create the process.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was even getting stuff like:
|
||
cls.set_demangler(cls.default_demangler) | ||
cls.demangler_proc.stdin.write((name + "\n").encode("utf-8")) | ||
cls.demangler_proc.stdin.flush() | ||
return cls.demangler_proc.stdout.readline().rstrip().decode("utf-8") | ||
|
@@ -323,8 +325,6 @@ def get_remarks(input_file, filter_=None): | |
def gather_results(filenames, num_jobs, should_print_progress, filter_=None): | ||
if should_print_progress: | ||
print("Reading YAML files...") | ||
if not Remark.demangler_proc: | ||
Remark.set_demangler(Remark.default_demangler) | ||
remarks = optpmap.pmap( | ||
get_remarks, filenames, num_jobs, should_print_progress, filter_ | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I 100% agree with that.