I need to write a programm which uses threads and sockets. What is the best way to do it for different platforms (Linux, Windows, Mac).
I know about POSIX, but there is no POSIX on Win.
Are there any libraries handling that in a platform independent way?
If you really want C (not C++), I suggest to use the standard POSIX threads on non-Windows platforms, and use pthreads-win32 on Windows. It supports both 32- and 64-bit, both MSVC and MinGW. It’s current version (2.9.1) was released just one month ago, so the project is actively maintained. There’s also a fork on github with some fixes in MSVC2010 project.
If C++ is also an option, I’d choose boost, because it’s where the standard c++ evolves (the design of
std::threadin c++11 is an evolution fromboost::thread, etc.)For the network part of your question,
boost::asiois the best choice if C++ is OK for you, otherwise didn’t see anything comparable in C. In particular,boost::asiosupportsI/O Completion Ports (IOCP)on Windows, which is critical for performance.boost::asiorequires some time to learn, but in my personal opinion it worth every minute spent reading the documentation (which is great) and working with examples.