makes incremental collection easier. Was enabled by default until 6.0.
Rarely used, to my knowledge.
-NO_HANDLE_FORK (Unix only) Do not attempt to make GC_malloc() work in
- a child process fork()'ed from a multi-threaded parent. (Might be required
- if pthread_atfork is missing.)
+HANDLE_FORK (Unix and Cygwin only) Attempt by default to make GC_malloc()
+ work in a child process fork()'ed from a multi-threaded parent. Not fully
+ POSIX-compliant and could be disabled at runtime (before GC_INIT).
TEST_WITH_SYSTEM_MALLOC Causes gctest to allocate (and leak) large
chunks of memory with the standard system malloc. This will cause the root
&& ((defined(GC_PTHREADS) && !defined(HURD) && !defined(NACL) \
&& !defined(PLATFORM_ANDROID) && !defined(GC_WIN32_PTHREADS) \
&& !defined(USE_WINALLOC)) \
- || defined(HANDLE_FORK))
+ || (defined(DARWIN) && defined(MPROTECT_VDB)) || defined(HANDLE_FORK))
/* Attempts (where supported and requested) to make GC_malloc work in */
/* a child process fork'ed from a multi-threaded parent. */
# define CAN_HANDLE_FORK
# ifdef CAN_HANDLE_FORK
if (!GC_is_initialized)
GC_handle_fork = (GC_bool)value;
-# elif defined(THREADS)
- /* FIXME: Handle Darwin case. */
+# elif defined(THREADS) || (defined(DARWIN) && defined(MPROTECT_VDB))
if (!GC_is_initialized && value)
ABORT("fork() handling disabled");
+# else
+ /* No at-fork handler is needed in the single-threaded mode. */
# endif
}
pthread_attr_t attr;
exception_mask_t mask;
+# ifdef CAN_HANDLE_FORK
+ if (GC_handle_fork) {
+ /* To both support GC incremental mode and GC functions usage in */
+ /* the forked child, pthread_atfork should be used to install */
+ /* handlers that switch off GC_dirty_maintained in the child */
+ /* gracefully (unprotecting all pages and clearing */
+ /* GC_mach_handler_thread). For now, we just disable incremental */
+ /* mode if fork() handling is requested by the client. */
+ if (GC_print_stats)
+ GC_log_printf(
+ "GC incremental mode disabled since fork() handling requested\n");
+ return;
+ }
+# endif
+
if (GC_print_stats == VERBOSE)
GC_log_printf(
"Initializing mach/darwin mprotect virtual dirty bit implementation\n");
if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
ABORT("pthread_attr_setdetachedstate failed");
-# if defined(HANDLE_FORK) && !defined(THREADS)
- /* FIXME: See comment in GC_fork_prepare_proc. */
-# endif
-
# undef pthread_create
/* This will call the real pthread function, not our wrapper */
if (pthread_create(&thread, &attr, GC_mprotect_thread, NULL) != 0)
/* Wait for an ongoing GC to finish, since we can't finish it in */
/* the (one remaining thread in) the child. */
LOCK();
-# if defined(GC_DARWIN_THREADS) && defined(MPROTECT_VDB)
- if (GC_dirty_maintained) {
- WARN("GC incremental mode is incompatible with fork() for now\n", 0);
- /* Currently, it is not allowed to use any GC allocated data */
- /* or call any GC function in the child (before exec). */
- /* FIXME: Remove warning when mode implemented in child_proc. */
- }
-# endif
DISABLE_CANCEL(fork_cancel_state);
/* Following waits may include cancellation points. */
# if defined(PARALLEL_MARK)
# if defined(PARALLEL_MARK)
if (GC_parallel)
GC_release_mark_lock();
-# endif
-# if defined(GC_DARWIN_THREADS) && defined(MPROTECT_VDB)
- /* FIXME: Since GC_mprotect_thread is not running in the child, */
- /* GC_dirty_maintained should be switched off gracefully */
- /* (unprotecting all pages and clearing GC_mach_handler_thread). */
# endif
GC_remove_all_threads_but_me();
# ifdef PARALLEL_MARK