Skip to content

Declare TypedData with RUBY_TYPED_THREAD_SAFE_FREE - #222

Merged
kou merged 1 commit into
ruby:masterfrom
byroot:thread-safe-free
Jul 12, 2026
Merged

Declare TypedData with RUBY_TYPED_THREAD_SAFE_FREE#222
kou merged 1 commit into
ruby:masterfrom
byroot:thread-safe-free

Conversation

@byroot

@byroot byroot commented Jul 12, 2026

Copy link
Copy Markdown
Member

Available on Ruby 4.1: [Feature #22067]

Ref: https://bugs.ruby-lang.org/issues/22067

When available this flag superseed RUBY_TYPED_FREE_IMMEDIATELY and allow parallel sweeping of the type.

Available on Ruby 4.1: [Feature #22067]

Ref: https://bugs.ruby-lang.org/issues/22067

When available this flag superseed RUBY_TYPED_FREE_IMMEDIATELY
and allow parallel sweeping of the type.
@kou
kou merged commit 8d27a7f into ruby:master Jul 12, 2026
68 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Jul 12, 2026
(ruby/stringio#222)

Available on Ruby 4.1: [Feature #22067]

Ref: https://bugs.ruby-lang.org/issues/22067

When available this flag superseed RUBY_TYPED_FREE_IMMEDIATELY and allow
parallel sweeping of the type.

ruby/stringio@8d27a7f4f1
Comment thread ext/stringio/stringio.c
strio_free(void *p)
{
struct StringIO *ptr = p;
if (--ptr->count <= 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a thread unsafe pattern we need to look out for. If we free these in parallel (or concurrently with the mutator) we'll race on the count

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh good catch, sorry I overlooked that refcount :/

I suppose we could use anatomic, but might not be worth it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All good ❤️

#223

@byroot
byroot deleted the thread-safe-free branch July 29, 2026 20:41
kou pushed a commit that referenced this pull request Aug 1, 2026
Follow up to #222

This refcount previously wasn't thread safe (and shouldn't have been
declared `RUBY_TYPED_THREAD_SAFE_FREE`), but it's easy enough to fix
using ruby/atomic.h (Ruby 3.0+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants