Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer Windows threads to pthreads #1207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Marc-Aldorasi-Imprivata

On mingw ASIO can only detect pthreads if the pthread header is included before it. Since mingw can use both pthreads and Windows threads, if you have multiple source files that access an io_context and only some of them include pthreads before asio then they can use the wrong thread type and corrupt memory. If asio instead prefers Windows threads to pthreads there will be no type confusion and no memory corruption.

The following program demonstrates the difference:

#if INCLUDE_PTHREAD
#include <pthread.h>
#endif
#include <asio.hpp>
#include <iostream>

int main() {
	std::cout << "asio::detail::thread is " << typeid(asio::detail::thread).name() << '\n';
}

When compiled with -DINCLUDE_PTHREAD it prints "asio::detail::thread is N4asio6detail12posix_threadE", but when compiled without that define prints "asio::detail::thread is N4asio6detail10win_threadE". With this patch it always prints "asio::detail::thread is N4asio6detail10win_threadE".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant