If you need pthreads for Windows MinGW projects, most projects used pthreads-win32 from Red Hat. However, it wasn't completely compatible with POSIX versions of pthreads. It also uses LGPL licensing which can be somewhat restrictive with MIT and BSD style licensed projects. So, the MinGW64 project wrote their own pthreads implementation from scratch which is available at the MinGW64 web site. Looking at the code, I wasn't sure if the MinGW64 pthreads implementation would work with the MinGW (www.mingw.org) 32 bit compiler as is or if it would need patching. So, I decided to use another alternative for my own projects. Another option on Windows is the midipix project which uses the musl C library pthread implementation.

Many libraries including musl add C11 and C++11 thread support using their POSIX thread implementations. That's because pthreads were available long before the C11 standards were created.

I wanted a simple, cross-platform portable implementation of pthreads. I also wanted to learn more about threads especially C11 threading standards. So, I wrote my own C11 threads library and a pthreads implementation based on it. C11 threads seem more concise, so I wanted to implement C11 support independent of pthreads and then tried implementing pthreads using C11 threads. My library mainly uses semaphores (which are available on most systems). I've read that systems like Haiku exclusively use semaphores for synchronization. While the library is written for portability, I haven't finished adding code or testing for certain platforms. I have used my threading libraries when building MinGW (my own 32 bit version of the compiler) with C++11 threading support enabled.

Before I wrote my library, I used c11threads and TinyCThread with various projects I was porting to fill the gap in support for C11 and C++11 threads. Both are useful if you don't have other alternatives. Now, that I've built MinGW with my own thread libraries, I haven't had any major issues with C11, C++11 and POSIX thread support.

Here are some links I like related to thread libraries and implementations.

Interesting article on semaphores also some source code examples:
http://preshing.com/20150316/semaphores-are-surprisingly-versatile/

Article on benaphores with sample code:
http://preshing.com/20120226/roll-your-own-lightweight-mutex/

Recursive mutex using benaphores with sample code:
http://preshing.com/20120305/implementing-a-recursive-mutex/

Haiku - articles on Condition Variables
https://www.haiku-os.org/legacy-docs/benewsletter/Issue4-39.html
https://www.haiku-os.org/legacy-docs/benewsletter/Issue4-40.html

pthreads-win32
http://sourceware.org/pthreads-win32/

Bionic C library pthreads implementation
https://android.googlesource.com/platform/bionic/+/master/libc/bionic/

Haiku pthread implementation
https://github.com/luciang/haiku/tree/master/src/system/libroot/posix/pthread

TinyCThread
C11 threads implementation
https://tinycthread.github.io/

c11threads
GNU compatibility headers for C11 thread support
https://github.com/jtsiomb/c11threads

Upthreads
A user space implementation of the POSIX thread library implemented using setjmp/longjump (or equivalent).
http://upthread.sourceforge.net/

MinGW

May. 5th, 2016 12:29 pm
There are now several forks of MinGW and each has its pros and cons. However, there are now enough negatives to using them, that I've found it necessary to build MinGW from scratch myself. The MinGW64 project uses a later version of gcc, has better compatibility for building Open Source projects and has its own thread library instead of using Red Hat's pthreads-w32. Some custom builds of MinGW64 even have POSIX threading set as the default instead of Win32 threading. That means better compatibility for C++ thread related code (since the GNU C++ library relies on POSIX threading for parts of its implementation). The MinGW project has always been more careful about licensing and making sure that the code it was using was properly licensed and legal for usage. The MinGW project did follow the example of the MinGW64 project in one key area. They switched from public domain to a MIT license for their runtime library and Win32 API. When they did so without clearly indicating that an exception could be made similar to the GNU gcc runtime license exception, I felt it was time to stop using that version of the MinGW compiler.

I'm currently working with gcc 4.9.2 compiled from source. I'm still using the older public domain APIs, but I've made several modifications for compatibility with the Win32 API (including some modifications that aren't available in the MinGW64 libraries). I have a minimal thread library that was custom written for portability. It's based on C11 thread support and includes POSIX functionality. The gnu compiler is built with POSIX threads as the default so C++ threading works as expected.

So far, I've had no reason to want to work with any other MinGW forks. The version I have does everything I need and supports all the programs I want to compile on Windows. My particular fork is continually evolving. I continue to add support for new Win32 API changes, Win32 API omissions, new C/C++ features as I need them. At some point, I hope to completely replace the runtime library with code that better supports internationalization (better UTF-8 support), C standard compatibility and other useful features.

If anyone else is finding limitations with the compilers maintained by the various MinGW and MinGW64 projects or other related forks based on these projects, I highly recommending building the GNU compiler from source on your own with the options you need most. If you're interested in discussing the GNU compiler further or want to know more about my modifications, you're welcome to use the CppDesign mailing list ( http://groups.yahoo.com/group/CppDesign ) as a forum for further discussion.

April 2025

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
27282930   

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 24th, 2025 06:21 pm
Powered by Dreamwidth Studios