File tree 2 files changed +12
-0
lines changed
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -463,6 +463,7 @@ static void caml_thread_remove_and_free(caml_thread_t th)
463
463
464
464
static void caml_thread_reinitialize (void )
465
465
{
466
+ struct channel * chan ;
466
467
caml_thread_t th , next ;
467
468
468
469
th = Active_thread -> next ;
@@ -484,6 +485,16 @@ static void caml_thread_reinitialize(void)
484
485
s->lock (busy = 1) */
485
486
struct caml_locking_scheme * s = atomic_load (& Locking_scheme (Caml_state -> id ));
486
487
s -> reinitialize_after_fork (s -> context );
488
+
489
+ /* Reinitialize IO mutexes, in case the fork happened while another thread
490
+ had locked the channel. If so, we're likely in an inconsistent state,
491
+ but we may be able to proceed anyway. */
492
+ caml_plat_mutex_init (& caml_all_opened_channels_mutex );
493
+ for (chan = caml_all_opened_channels ;
494
+ chan != NULL ;
495
+ chan = chan -> next ) {
496
+ caml_plat_mutex_init (& chan -> mutex );
497
+ }
487
498
}
488
499
489
500
CAMLprim value caml_thread_join (value th );
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ CAMLextern void (*caml_channel_mutex_unlock) (struct channel *);
105
105
CAMLextern void (* caml_channel_mutex_unlock_exn ) (void );
106
106
107
107
CAMLextern struct channel * caml_all_opened_channels ;
108
+ CAMLextern caml_plat_mutex caml_all_opened_channels_mutex ;
108
109
109
110
#define Lock (channel ) \
110
111
if (caml_channel_mutex_lock != NULL) (*caml_channel_mutex_lock)(channel)
You can’t perform that action at this time.
0 commit comments