Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pthreads in Visual C++

I'm experimenting with multithreading in Windows and was wondering whether I should

  • use Win32 API
  • use POSIX Threads for Windows

Learning Pthreads would be useful if I tried to develop such applications on different platforms - but am I losing anything by not learning Win32 API? Or are both similar enough so that learning one allows me to figure out the other easily?

like image 876
Jacob Avatar asked Mar 08 '10 18:03

Jacob


2 Answers

  1. Use Boost Threads. When C++0x comes along, we will have std::threads. Boost threads has the closest implementation to std threads.

  2. else use pthreads. Pthreads is second closest to std::threads, and formed the main basis of std threads and boost threads.

  3. else do windows threading directly. You can still learn how threads work, and form a mental model of things. It just tends to use synchronization primitives that are a bit non-standard.

like image 167
tony Avatar answered Nov 12 '22 07:11

tony


If you're going to do much Windows programming, it will pay to learn the basic Win32 threading constructs: critical sections, interlocked functions, CreateThread, WaitFor*Object, etc. These aren't hard to understand, and they translate transparently to equivalent objects in other threading frameworks.

However, for more advanced threading constructs such as semaphores, events, etc., I would use the pthreads library, since the documentation on those tends to be clearer and examples more abundant.

like image 26
JSBձոգչ Avatar answered Nov 12 '22 05:11

JSBձոգչ