Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

CI Category Build on OS Host OS Build Status
Travis CI 🥇Primary Ubuntu Trusty Windows Vista Build Status
Tea CI 🥇Primary Wine Windows Vista Build Status



MCF Gthread 是为 Windows 7 及更高版本的 Windows 设计的高效 Gthread 实现,用于移植 GCC 的用途。
MCF Gthread is a Gthread implementation for Windows 7 and above that meets the requirements of Gthread interfaces, playing a role as a replacement for the (currently working but smelly and inefficient) gthr-win32 implementation when porting GCC.

C++0x 线程支持处于实验阶段。
The C++0x thread support is currently experimental.
All the other features including once-initialization, mutex, recursive mutex, condition variable and thread local storage (TLS) have been implemented.

该项目是从 MCF CRT 中 fork 出来的。
This project was forked from MCF CRT.

该项目目前仅在 x86 和 x64 下开发以及测试,其它处理器架构未有验证。
This project is developed and tested under x86 and x64 and hasn't been tested on other CPU architectures.

该项目使用了很多未有微软文档的系统调用来保证运行效率,因此并无法保证在未来的 Windows 版本中仍然能够正常工作。
This project uses a number of undocumented NT system calls for efficiency reasons and may be broken in future Windows versions.
The author gives no warranty for this project. Use it at your own risk.


How to build

我们建议你在 MSYS2 中编译这个项目。你可以在 这里 下载。
We suggest you build this project in MSYS2, which can be obtained here.

如果你刚刚安装 MSYS2,你需要一些基本的开发工具包。如果你已经有 MSYS2 的开发环境请跳过这一步:
If you have just installed a fresh MSYS2, you would have to install a few development packages. You may skip this step if you have already had MSYS2 development environment set up:

$ pacman -Sy
$ pacman -S base-devel mingw-w64-{i686,x86_64}-toolchain --noconfirm
$ pacman -R gdb # Usually you should remove it because it is for MSYS2 programs and not for native programs.
                # You may install native GDB using the following command:
                #     pacman -S mingw-w64-{i686,x86_64}-gdb

假设当前目录是在该项目中,在 bash 中运行以下命令:
Assuming the working directory is this project, run the following commands in bash:

$ mkdir -p m4
$ autoreconf -i
$ ./configure
$ make -j4
$ ls *.dll.a

If the DLL is built successfully, you will see the follow file:


现在看看这个 DLL 是否正常工作:
Now check whether it is working:

$ gcc -std=c11 test/test.c -otest.exe -Isrc/env -L. -lmcfgthread
$ PATH=".:$PATH" ./test.exe

如果一切顺利,你将会看到类似这样的输出(TLS key 的值是机器相关的,而 TLS 的析构函数是乱序执行的):
If everything goes well you will see something like this (the value of the TLS key is machine-dependent and TLS destructors are executed out-of-order):

key = 00342D20
constructed tls data 0
waiting for thread 0
constructed tls data 1
constructed tls data 2
constructed tls data 3
destructing tls data 1
destructing tls data 3
destructing tls data 2
destructing tls data 0
waiting for thread 1
waiting for thread 2
waiting for thread 3
counter = 4000000

现在我们看到所有的 TLS 都被正确创建并析构,而受到互斥体保护的 counter 上并未出现数据竞争。祝贺你!
Now we can tell that all TLS slots have been constructed and destructed without leaks and the counter protected by a mutex has suffered from no data races. Cheers!

IRC channel:

You can’t perform that action at this time.