Skip to content

Commit

Permalink
Workaround pthread_rwlock_init() fail with EBUSY on OS X
Browse files Browse the repository at this point in the history
(fix of commit 3bfb499)

Issue #473 (bdwgc).

* pthread_support.c [CAN_HANDLE_FORK && USE_PTHREAD_LOCKS
&& !GC_WIN32_THREADS && USE_RWLOCK] (fork_child_proc): Update comment.
* pthread_support.c [CAN_HANDLE_FORK && USE_PTHREAD_LOCKS
&& !GC_WIN32_THREADS && USE_RWLOCK && DARWIN] (fork_child_proc): Do
not call pthread_rwlock_init(); reset GC_allocate_ml to
PTHREAD_RWLOCK_INITIALIZER instead; add comment.
  • Loading branch information
ivmai committed Oct 13, 2023
1 parent 45a71e7 commit 1a0c94c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,13 +1443,22 @@ GC_INNER void GC_wait_for_gc_completion(GC_bool wait_for_all)
GC_ASSERT(I_DONT_HOLD_LOCK());
/* Reinitialize the mutex. It should be safe since we are */
/* running this in the child which only inherits a single thread. */
/* mutex_destroy() may return EBUSY, which makes no sense, but */
/* that is the reason for the need of the reinitialization. */
/* pthread_mutex_destroy() and pthread_rwlock_destroy() may */
/* return EBUSY, which makes no sense, but that is the reason for */
/* the need of the reinitialization. */
/* Note: excluded for Cygwin as does not seem to be needed. */
# ifdef USE_RWLOCK
(void)pthread_rwlock_destroy(&GC_allocate_ml);
if (pthread_rwlock_init(&GC_allocate_ml, NULL) != 0)
ABORT("pthread_rwlock_init failed (in child)");
# ifdef DARWIN
/* A workaround for pthread_rwlock_init() fail with EBUSY. */
{
pthread_rwlock_t rwlock_local = PTHREAD_RWLOCK_INITIALIZER;
BCOPY(&rwlock_local, &GC_allocate_ml, sizeof(GC_allocate_ml));
}
# else
if (pthread_rwlock_init(&GC_allocate_ml, NULL) != 0)
ABORT("pthread_rwlock_init failed (in child)");
# endif
# else
(void)pthread_mutex_destroy(&GC_allocate_ml);
/* TODO: Probably some targets might need the default mutex */
Expand Down

0 comments on commit 1a0c94c

Please sign in to comment.