Skip to content

Fix deadlock in multithreaded fork in OS X.#1

Merged
petermattis merged 1 commit intocrl-release-4.5.0from
pmattis/os-x-deadlock
Mar 17, 2019
Merged

Fix deadlock in multithreaded fork in OS X.#1
petermattis merged 1 commit intocrl-release-4.5.0from
pmattis/os-x-deadlock

Conversation

@petermattis
Copy link

On OS X, we rely on the zone machinery to call our prefork and postfork
handlers.

In zone_force_unlock, we call jemalloc_postfork_child, reinitializing all our
mutexes regardless of state, since the mutex implementation will assert if the
tid of the unlocker is different from that of the locker. This has the effect
of unlocking the mutexes, but also fails to wake any threads waiting on them in
the parent.

To fix this, we track whether or not we're the parent or child after the fork,
and unlock or reinit as appropriate.

This resolves jemalloc#895.

On OS X, we rely on the zone machinery to call our prefork and postfork
handlers.

In zone_force_unlock, we call jemalloc_postfork_child, reinitializing all our
mutexes regardless of state, since the mutex implementation will assert if the
tid of the unlocker is different from that of the locker.  This has the effect
of unlocking the mutexes, but also fails to wake any threads waiting on them in
the parent.

To fix this, we track whether or not we're the parent or child after the fork,
and unlock or reinit as appropriate.

This resolves jemalloc#895.
@petermattis petermattis requested review from bdarnell and tbg March 15, 2019 14:20
@petermattis
Copy link
Author

petermattis commented Mar 15, 2019

I haven't been able to reproduce the lock up when running on top of this patch. Seems safer to back port this patch, than to try and upgrade jemalloc. Note that affected code only runs on Darwin.

@tbg
Copy link
Member

tbg commented Mar 15, 2019

LGTM

@petermattis petermattis merged commit 80ddaec into crl-release-4.5.0 Mar 17, 2019
@petermattis petermattis deleted the pmattis/os-x-deadlock branch March 17, 2019 00:24
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.

4 participants