Skip to main content

GC_register_my_thread

Function GC_register_my_thread 

Source
pub unsafe extern "C" fn GC_register_my_thread(
    arg1: *const GC_stack_base,
) -> c_int
Expand description

Register the current thread, with the indicated stack bottom, as a new thread whose stack(s) should be traced by the collector. If it is not implicitly called by the collector, this must be called before a thread can allocate garbage-collected memory, or assign pointers to the garbage-collected heap. Once registered, a thread will be stopped during garbage collections. This call must be previously enabled (see GC_allow_register_threads). This should never be called from the main thread, where it is always done implicitly. This is normally done implicitly if GC_ functions are called to create the thread, e.g. by include gc.h file (which redefines some system functions) before calling the system thread creation function. Nonetheless, thread cleanup routines (e.g., pthreads key destructor) typically require manual thread registering (and unregistering) if pointers to GC-allocated objects are manipulated inside. It is also always done implicitly on Win32 platform if GC_use_threads_discovery() is called at start-up. Except for the latter case, the explicit call is normally required for threads created by third-party libraries. A manually registered thread requires manual unregistering. Returns GC_SUCCESS on success, GC_DUPLICATE if already registered.