Skip to content
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

Use main_thread->ec from rb_vm_main_ractor_ec #9311

Merged
merged 2 commits into from
Dec 21, 2023

Conversation

jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Dec 20, 2023

rb_vm_main_ractor_ec was introduced to allow rb_postponed_job_* to work when fired on non-Ruby threads, which have no EC set, and that is its only use.

When RUBY_MN_THREADS=1 is set ractor->threads.running_ec is NULL when the shared thread is sleeping. This instead grabs the EC directly from the main thread which seems to always be set.

With this change StackProf works with RUBY_MN_THREADS=1 set (this should fix tmm1/stackprof#221)

Fixes [Bug #20016]

cc @byroot @ko1 @KJTsanaktsidis @tenderlove
cc @ivoanjo I noticed DataDog/dd-trace-rb#3259 does this change fix the issue for ddtrace?

jhawthorn and others added 2 commits December 20, 2023 15:44
rb_vm_main_ractor_ec was introduced to allow rb_postponed_job_* to work
when fired on non-Ruby threads, which have no EC set, and that is its
only use.

When RUBY_MN_THREADS=1 is set ractor->threads.running_ec is NULL when
the shared thread is sleeping. This instead grabs the EC directly from
the main thread which seems to always be set.

Fixes [Bug #20016]

Co-authored-by: Dustin Brown <[email protected]>
Copy link
Contributor

@KJTsanaktsidis KJTsanaktsidis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me I think - main_thread is set in exactly two places (VM bootstrap and after forking) so it should always be available for use in postponed job execution.

NEWS.md Show resolved Hide resolved
@jhawthorn jhawthorn merged commit 1f03042 into ruby:master Dec 21, 2023
98 checks passed
@jhawthorn jhawthorn deleted the main_ractor_ec_mn_fix branch December 21, 2023 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3.3.0-dev: Segfault in rb_profile_frames with N:M threads enabled
3 participants