PDA

Click to See Complete Forum and Search --> : Threading in C++


blackeyed
Dec 9th, 2002, 06:09 AM
can you please let me know how to make threads in c/c++.

CornedBee
Dec 9th, 2002, 09:36 AM
Two approaches:
a) OS-dependent: threading is something highly OS-dependent. POSIX threads work completly different than Windows threads.
For windows, look at the CreateThread function and related functions, as well as _beginthread and _beginthreadex. For POSIX look at clone.
This let's you wield the full power that the OS offers, but you can't write portable code this way.

b) OS-independent: the boost project ( www.boost.org ) has a C++ class library that offers a platform independent interface to threading. The advantage is portable code that integrates well with the C++ Standard Library. The disadvantage is that it is more or less the largest common denominator: It supports mutexes and critical sections, but not much more in the way of synchronization, and I don't know if it has thread local storage. But for simple console-based multi-threaded apps it's perfect.