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

Reinitialize IO mutexes in systhreads5 #2160

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ocaml/otherlibs/systhreads/st_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ static void caml_thread_remove_and_free(caml_thread_t th)

static void caml_thread_reinitialize(void)
{
struct channel * chan;
caml_thread_t th, next;

th = Active_thread->next;
Expand All @@ -484,6 +485,16 @@ static void caml_thread_reinitialize(void)
s->lock (busy = 1) */
struct caml_locking_scheme *s = atomic_load(&Locking_scheme(Caml_state->id));
s->reinitialize_after_fork(s->context);

/* Reinitialize IO mutexes, in case the fork happened while another thread
had locked the channel. If so, we're likely in an inconsistent state,
but we may be able to proceed anyway. */
caml_plat_mutex_init(&caml_all_opened_channels_mutex);
for (chan = caml_all_opened_channels;
chan != NULL;
chan = chan->next) {
caml_plat_mutex_init(&chan->mutex);
}
}

CAMLprim value caml_thread_join(value th);
Expand Down
1 change: 1 addition & 0 deletions ocaml/runtime/caml/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ CAMLextern void (*caml_channel_mutex_unlock) (struct channel *);
CAMLextern void (*caml_channel_mutex_unlock_exn) (void);

CAMLextern struct channel * caml_all_opened_channels;
CAMLextern caml_plat_mutex caml_all_opened_channels_mutex;

#define Lock(channel) \
if (caml_channel_mutex_lock != NULL) (*caml_channel_mutex_lock)(channel)
Expand Down
Loading