Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic multi-threading in C / C++ -- hints, advice, tutorial, some direction? [closed]

I would like to learn how to build a multi-threaded application, but I don't even really know where to start.

How do most people implement multi-threading? Do they use the boost library? Is there some other way to do it? (using standard C / C++)

I understand the concept, but totally have no idea where to even start to actually learn how to do it. Can anyone recommend anything?

http://msdn.microsoft.com/en-us/library/7t9ha0zh%28v=VS.80%29.aspx <--- Are these standard C++, or some Microsoft-only implementation?

Am I correct that the multithreading libraries are contained in the Windows API? I found an example on MSDN ( http://msdn.microsoft.com/en-us/library/esszf9hw%28v=VS.80%29.aspx) and the functions it uses (ReleaseMutex, etc) seem to be in windows.h. Is this what most people are using when they do Windows programming?

like image 439
Russel Avatar asked Aug 04 '10 05:08

Russel


2 Answers

Boost library is a cross-platform way of using threads.

Most people use winapi or pthreads. pthreads was originally used on POSIX systems but there is a port of it for mingw allowing its use on windows too.

I'd recommend using boost if you absolutely need cross-platform solution, or already have boost libraries linked. If you are developing for windows or POSIX, use winapi or pthreads correspondingly.

like image 67
Basilevs Avatar answered Sep 28 '22 17:09

Basilevs


If you are looking for a simple performance boost for in your application through multi-threading OpenMP is a simple library that will allow your program to scale across multiple cores, requiring only #pragma placement in your code to parallelize blocks of code or loops, with additional options to weak specific performance.

This doesn't easily allow for coarse parallelism like a GUI/processing/IO division in the application, but does allow for easily visible multi-threading performance boosts on multi-core machines in heavy number-crunching.

like image 34
phoenixillusion Avatar answered Sep 28 '22 17:09

phoenixillusion