-
Notifications
You must be signed in to change notification settings - Fork 30
How the MCF thread model works
LIU Hao edited this page Nov 30, 2024
·
5 revisions
The now committed patch implements compiler, linker and standard library support for the MCF thread model. The CRT part has not been committed to mingw-w64.
If GCC is configured with --enable-threads=mcf
:
- It has
__USING_MCFGTHREAD__
as a pre-defined macro, which enables special code paths in libstdc++ and mingw-w64 CRT. - It has
-lmcfgthread -lntdll
as default libraries. (NTDLL is only needed for static linking.) - It installs 'gthr-mcf.h' as 'bits/gthr-default.h', which is just a wrapper for 'mcfgthread/gthr.h'.
In libgcc, most use of threading infrastructure is internal. In libstdc++, there are some public functions, which, when __USING_MCFGTHREAD__
is defined, should be redirected to MCF implementations:
-
__cxa_thread_atexit(dtor, obj, dso)
: On Linux it is provided in libstdc++ and jumps to__cxa_thread_atexit_impl(dtor, obj, dso)
in libc. Recent mingw-w64 provides this function, so it should be opted out to prefer the mingw-w64 one. -
__cxa_guard_acquire(guard)
: On Linux it is implemented with futex. On most other platforms it is implemented with a single static mutex. It should be opted to call__MCF_cxa_guard_acquire(guard)
. -
__cxa_guard_release(guard)
: It is opted to call__MCF_cxa_guard_release(guard)
. -
__cxa_guard_abort(guard)
: It is opted to call__MCF_cxa_guard_abort(guard)
.
The mingw-w64 CRT needs these changes:
- Some process-termination routines in the Microsoft CRT effect non-standard behavior and have to be replaced (https://github.com/msys2/MINGW-packages/issues/2519). Because the Microsoft
exit()
should not be called any more, it is necessary to flush standard files after static destructors. This is done by calling__MCF_cxa_atexit(fflush, NULL, &__dso_handle)
before__main()
. - If a DLL entry-point function receives a
DLL_PROCESS_DETACH
notification, it shall call__MCF_cxa_finalize(&__dso_handle)
, as specified by the Itanium C++ ABI. -
_Exit(status)
: It is opted to call__MCF__Exit(status)
. -
_exit(status)
: It is equivalent to_Exit(status)
, and is opted to call__MCF__Exit(status)
. -
at_quick_exit(func)
: This function is linked statically by each module, and is opted to call__MCF_cxa_at_quick_exit(func, NULL, &__dso_handle)
. -
__cxa_at_quick_exit(dtor, obj, dso)
: It is opted to call__MCF_cxa_at_quick_exit(dtor, obj, dso)
. -
quick_exit(status)
: It is opted to call__MCF_quick_exit(status)
. -
atexit(func)
: This function is linked statically by each module, and is opted to call__MCF_cxa_atexit(func, NULL, &__dso_handle)
. -
__cxa_atexit(dtor, obj, dso)
: It is opted to call__MCF_cxa_atexit(dtor, obj, dso)
. -
exit(status)
: It is opted to call__MCF_exit(status)
. -
__cxa_finalize(dso)
: It is opted to call__MCF_cxa_finalize(dso)
. -
__cxa_at_thread_exit(dtor, obj, dso)
: It is opted to call__MCF_cxa_at_thread_exit(dtor, obj, dso)
.