Skip to content

How the MCF thread model works

LIU Hao edited this page Nov 17, 2024 · 5 revisions

Overview

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:

  1. It has __USING_MCFGTHREAD__ as a pre-defined macro, which enables special code paths in libstdc++ and mingw-w64 CRT.
  2. It has -lmcfgthread -lntdll as default libraries. (NTDLL is only needed for static linking.)
  3. 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 that are to be replaced with MCF implementations:

  1. __cxa_thread_atexit(): On Linux it is provided in libstdc++ and jumps to __cxa_thread_atexit_impl() in libc. Recent mingw-w64 provides this function, so it is opted out to prefer the mingw-w64 one. (There's a bug about it: https://github.com/msys2/MINGW-packages/issues/2519)
  2. __cxa_guard_acquire(), __cxa_guard_release() and __cxa_guard_abort(): On Linux they are implemented with futexes. On most other platforms they are implemented with a single static mutex. They call __MCF_cxa_guard_acquire(), __MCF_cxa_guard_release() and __MCF_cxa_guard_abort(), respectively.
Clone this wiki locally