Threads

Jul 22, 2011 at 11:28pm
Hello,

I hope this is where i should post this doubt...

In my college course the c++ class i took worked only with Microsoft Windows and Microsoft Windows functions program related, but now during summer break i would like to do some works that could be multi platform ( don't know if this is the expression ), meaning, running smoothly on Microsoft Windows or Linux or even MacOs( tough i am unaware if its possible to create programs/software in c++ for MacOs).

In my first project i will need to use threads. I know how to use threads in a Microsoft Windows environment, but, can i do the same if i want the program to run in Linux for example? Or this won't work and i have to write a program for Linux and other for Windows?

Thank you in advance for the help.
Jul 22, 2011 at 11:40pm
Windows, Linux, and MacOS all support multithreading environments.
You also can use C++ to write programs on all those platforms.

The tricky part is that how you write threading code can vary between platforms.

For example, WinAPI offers threading functions like CreateThread(), however those are available on Windows only and will not work if you try to compile on Linux or Mac.

You will probably need to use a cross-platform threading lib like pthreads (can be found on google). I know that works for Linux/Mac, and I think it also has implementation on Windows, too.
Jul 23, 2011 at 2:33am
I recommend Boost threading library. Its portable and the next version of standard C++ will be including boost style threads:

http://www.boost.org/doc/libs/1_47_0/doc/html/thread.html

EDIT:

You might even consider using a compiler that supports the new C++ standard threading library. I use GCC 4.6 which has the new standard thread library <thread>. I don't know about Microsoft compilers.
Last edited on Jul 23, 2011 at 2:40am
Topic archived. No new replies allowed.