Skip to content

Make the PosixShim errno field into a thread-local#5711

Merged
headius merged 1 commit intojruby:masterfrom
headius:thread_local_posix_shim_errno
Apr 25, 2019
Merged

Make the PosixShim errno field into a thread-local#5711
headius merged 1 commit intojruby:masterfrom
headius:thread_local_posix_shim_errno

Conversation

@headius
Copy link
Member

@headius headius commented Apr 25, 2019

In order to support concurrent reads and writes via the PosixShim,
we need to make errno be a thread-local. Some callers do their own
locking, releasing the lock before calling PosixShim, which causes
the errno updates and clears to step on other threads. It might be
possible to have those callers pass in their "unlock around" logic
as shown in #5706, but my first attempt did not work exactly right
and may introduces object overhead for stateful lambdas.

This implementation introduces thread-local read/write overhead to
all accessors of errno, but appears to be a clean way to keep this
field safe across concurrent IO operations.

Fixes #5706.

In order to support concurrent reads and writes via the PosixShim,
we need to make errno be a thread-local. Some callers do their own
locking, releasing the lock before calling PosixShim, which causes
the errno updates and clears to step on other threads. It might be
possible to have those callers pass in their "unlock around" logic
as shown in jruby#5706, but my first attempt did not work exactly right
and may introduces object overhead for stateful lambdas.

This implementation introduces thread-local read/write overhead to
all accessors of errno, but appears to be a clean way to keep this
field safe across concurrent IO operations.

Fixes jruby#5706.
@headius headius added this to the JRuby 9.2.8.0 milestone Apr 25, 2019
@enebo
Copy link
Member

enebo commented Apr 25, 2019

ship it! :)

@headius headius merged commit fd40550 into jruby:master Apr 25, 2019
@headius headius deleted the thread_local_posix_shim_errno branch April 25, 2019 16:00
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.

IO.read_nonblock raises EOFError with concurrent reads

2 participants