Coder Social home page Coder Social logo

exhorder / mingw-std-threads Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meganz/mingw-std-threads

0.0 1.0 0.0 305 KB

Standard threads implementation currently still missing on MinGW GCC on Windows

License: BSD 2-Clause "Simplified" License

C++ 99.85% CMake 0.15%

mingw-std-threads's Introduction

mingw-std-threads

Standard C++11 threading classes implementation, which are currently still missing on MinGW GCC.

Windows compatibility

This implementation should work with Windows XP (regardless of service pack), or newer. The library automatically detects the version of Windows that is being targeted, and selects an implementation that takes advantage of available Windows features. In MinGW GCC, the target Windows version may optionally be selected by the command-line option -D _WIN32_WINNT=.... Use 0x0600 for Windows Vista, or 0x0601 for Windows 7. See "Modifying WINVER and _WIN32_WINNT.

Usage

This is a header-only library. To use, just include the corresponding mingw.xxx.h file, where xxx would be the name of the standard header that you would normally include. For additional mutex helper classes, such as std::scoped_guard or std::unique_lock, you need to include <mutex> before including mingw.mutex.h

Compatibility

This code has been tested to work with MinGW-w64 5.3.0, but should work with any other MinGW version that has the std threading classes missing, has C++11 support for lambda functions, variadic templates, and has working mutex helper classes in <mutex>.

Switching from the win32-pthread based implemetation

It seems that recent versions of mingw-w64 include a win32 port of pthreads, and have the std::thread, std::mutex etc classes implemented and working, based on that compatibility layer. This is a somewhat heavier implementation, as it brings a not very thin abstraction layer. So you may still want to use this implementation for efficiency purposes. Unfortunately you can't use it standalone and independent of the system <mutex> header, as it relies on it for std::unique_lock and other non-trivial utility classes. In that case you will need to edit the c++-config.h file of your MinGW setup and comment out the definition of _GLIBCXX_HAS_GTHREADS. This will cause the system headers to not define the actual thread, mutex, etc classes, but still define the necessary utility classes.

Why MinGW has no threading classes

It seems that for cross-platform threading implementation, the GCC standard library relies on the gthreads/pthreads library. If this library is not available, as is the case with MinGW, the std::thread, std::mutex, std::condition_variable are not defined. However, higher-level mutex helper classes are still defined in <mutex> and are usable. Hence, this implementation does not re-define them, and to use these helpers, you should include <mutex> as well, as explained in the usage section.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.