Skip to content

Release GVL during matching#213

Merged
mudge merged 5 commits into
mainfrom
nogvl
Apr 9, 2026
Merged

Release GVL during matching#213
mudge merged 5 commits into
mainfrom
nogvl

Conversation

@mudge
Copy link
Copy Markdown
Owner

@mudge mudge commented Apr 8, 2026

Like the official RE2 Python bindings, release the Ruby Global VM Lock
when performing matches so work on other threads can continue.

Note that Abseil's synchronization primitives (SRWLOCK and
SleepConditionVariableSRW) are incompatible with Ruby's Win32
Mutex-based GVL, causing WAIT_ABANDONED crashes when multiple threads
match concurrently so the GVL is not released on Windows.

@mudge mudge force-pushed the nogvl branch 4 times, most recently from bff2040 to 3649f11 Compare April 9, 2026 09:45
mudge added 5 commits April 9, 2026 11:42
Like the official RE2 Python bindings, release the Ruby Global VM Lock
when performing matches so work on other threads can continue.

Note that Abseil's synchronization primitives (SRWLOCK and
SleepConditionVariableSRW) are incompatible with Ruby's Win32
Mutex-based GVL, causing WAIT_ABANDONED crashes when multiple threads
match concurrently so the GVL is _not_ released on Windows.
As with matching on RE2::Regexp objects, release the Ruby Global VM Lock
when performing a match with a compiled RE2::Set object.
To prevent bugs when re-initializing an RE2::Regexp or RE2::Set during a
match (especially now they can happen truly in parallel), freeze those
objects as soon as possible (on initialization for RE2::Regexp and on
compilation for RE2::Set).

Similarly, freeze any input strings ASAP before subsequent coercions to
prevent inputs being mutated before they are passed to the underlying
RE2 library.
Following on from matching with RE2::Regexp and RE2::Set, release the
Ruby Global VM Lock when performing a replace, global replace, or
extract.
reinterpret_cast is more powerful than we need when casting void * to
specific struct pointers.
@mudge mudge changed the title Try releasing GVL during matching Release GVL during matching Apr 9, 2026
@mudge mudge marked this pull request as ready for review April 9, 2026 10:53
@mudge mudge merged commit e342304 into main Apr 9, 2026
103 checks passed
@mudge mudge deleted the nogvl branch April 9, 2026 12:19
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.

1 participant