MINGW-W64 threading Model: POSIX vs Win32 (POSIX allows use of C++11 std:: thread, but with a winpthreads, additional DLLs may be required)

Source: Internet
Author: User
Tags mutex posix postgresql microsoft c



I am installing MINGW-W64 on Windows, there are two options: Win32 thread and POSIX thread. I know the difference between the Win32 thread and the pthreads, but I don't understand the difference between the two options. I suspect that if I choose a POSIX thread, it will prevent me from invoking a WINAPI function like CreateThread.



It seems that this option specifies which program or library will use which thread API, but through what? by gcc,libstdc++ or something else?



I found: What is the difference between Thread_posixs and thread_win32 gcc Windows port?


In short, for this version of the Mingw,threads-posix release will use the POSIX API and allow std: Thread,threads-win32 will use WIN32API and disable the standard Std::thread section.


OK, if I choose Win32 Thread, then Std::thread will not be available, but the Win32 thread will still be used. But with what?









The part of the GCC runtime (special exception handling) relies on the threading model being used. So if you're using a version of the runtime built with a POSIX thread, but decide to use the Win32 API to create threads in your own code, you might encounter some problems.



Even if you are using the Win32 thread version of the runtime, you probably should not call the Win32 API directly. References from MinGW frequently asked questions:


Because MinGW uses the standard Microsoft Runtime library that comes with Windows, you should be careful and use the correct functions to generate a new thread.CreateThreadfunction will not correctly set the stack for the run-time library. You should use_beginthreadex, it is (almost almost) fully compatibleCreateThread.








GCC comes with a compiler runtime library (Arial) that uses (one of these) to provide a multithreaded-related feature in its supported languages. The most relevant example is C++11 libstdc++, where<thread><mutex><future>GCC did not have a complete implementation of its internal Win32 threading model. MINGW-W64 provides winpthreads (a pthreads implementation on top of the Win32 multithreaded API), and GCC can link it to enable all the fantastic features.



I must emphasize that the option here does not allow you to write any code you want (it has absolutely no effect on the API that you can call in the code). It only reflects which runtimes are used by the (libgcc/libstdc++/...) library. Warnings referenced by @James are independent of the GCC threading model and are related to the CRT implemented by Microsoft.



Summarize:


    • posix: Enable the C++11/c11 multithreading feature. Make depend dependent on libwinpthreads so that you will distribute winpthreads even if you do not call the API directly. There is nothing wrong with using an application to distribute a DLL.
    • win32: No c++11 multithreading capability.


Does not affect any user code that calls the Win32 API or the Pthreads API. You can use two at a time.



Original Author:RUBENVB



https://ask.helplib.com/windows/post_675746



--------------------------------------------------------------------------------------------------------------- -----------



I have two options for installing MINGW-W64 on Windows: Win32 threads and POSIX threads. I know what the difference is between the Win32 thread and the pthreads, but I don't understand what the difference between the two options is. I suspect that if I would choose a POSIX thread, it would prevent me from calling functions like the CreateThread WINAPI.



It seems that this option specifies which thread API will be used by some programs or libraries, but by what? Through the Gulf Cooperation Council, LIBSTDC + + or other?



I found this: what is the difference between Windows GCC ports Thread_posixs and Thread_win32?


In summary, for this version of the Mingw,threads-posix version will use the POSIX API and allow the use of STD:: thread, and Threads-win32 will use the Win32 API and disable STD:: Part of the standard for thread.


OK, if I will select the Win32 thread, then std:: Thread will not be available, but will still use the Win32 thread. But with what?






GCC comes with a compiler runtime (LIBGCC), which is used (among other things) to provide a bottom-level operating system abstraction to support multilingual-related features. The most relevant examples are C + + for LIBSTDC + +,<thread><mutex>and when<future>building GCC using the internal WIN32 threading model, there is no complete implementation. MINGW-W64 provides a winpthreads (a pthreads implementation on top of the Win32 multithreaded API), and then GCC can link to all the odd features.



I must emphasize that this option does not prohibit you from writing any code you want (it has no effect on the APIs that you can invoke in your code). It only reflects the GCC runtime library (LIBGCC/LIBSTDC + +/...). ) using the feature. The warning @James Reference is independent of the internal threading model of GCC, regardless of the Microsoft CRT implementation.



Summarize:


    • posix: Enable the C + + 11/c11 multithreading feature. Makes LIBGCC dependent on libwinpthreads, so the Winpthreads DLL is distributed even if the pthreads API is not called directly. Assign a more DLL to your application without any problems.
    • win32: There is no C + + 11 multi-threading feature.


There is no effect on any user code that calls the Win32 API or the Pthreads API. You can always use both.



Part of the GCC runtime, especially exception handling, relies on the threading model being used. Therefore, if you are using a version of the runtime built with POSIX threads, but decide to use the Win32 API to create threads in your own code, there may be a problem at some point.



Even if you use the WIN32 thread version of the runtime, you may not want to call the Win32 API directly. From MinGW FAQ Reference:


Because MinGW uses the standard Microsoft C Runtime library that comes with Windows, you should be careful and use the correct functions to generate new threads. In particular, theCreateThreadfunction does not correctly set the stack for the C run-time library. You should use_beginthreadex, and (almost) withCreateThreadfull compatibility.


Note that you can now use some C + + std:: Thread in Win32 threading mode. These head-only adapters are available for me out of the box: https://github.com/meganz/mingw-std-threads



From the revision history, there have been some recent attempts to use it as part of the MINGW64 runtime.



https://code.i-harness.com/zh-CN/q/1071994



MINGW-W64 threading Model: POSIX vs Win32 (POSIX allows use of C++11 std:: thread, but with a winpthreads, additional DLLs may be required)


Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.