Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ multithreading tutorial [closed]

Is there a good tutorial on working with (programming) threads in Visual Studio 2005? Not MFC related, just native C++ (no .NET).

like image 998
lmsasu Avatar asked Nov 10 '08 20:11

lmsasu


People also ask

Is C good for multithreading?

C does not contain any built-in support for multithreaded applications. Instead, it relies entirely upon the operating system to provide this feature. This tutorial assumes that you are working on Linux OS and we are going to write multi-threaded C program using POSIX.

Is C single threaded?

C is a language that runs on one thread by default, which means that the code will only run one instruction at a time.

What is pthread_t?

pthread_t is the data type used to uniquely identify a thread. It is returned by pthread_create() and used by the application in function calls that require a thread identifier.

How many threads can be executed at a time?

4.2. Windows. On Windows machines, there's no limit specified for threads. Thus, we can create as many threads as we want, until our system runs out of available system memory.


2 Answers

Instead of using Win32 threads directly, I'd consider using a thread wrapper such as Boost threads. These are cross platform so porting your application later will be easier.

like image 186
Tom Leys Avatar answered Oct 17 '22 01:10

Tom Leys


You may take a look at the following OpenMP tutorials. This doesn't concern all concepts of multithreading in VC++, but OpenMP only, which VC++ supports. OpenMP is easy to use in some simple cases of multithreading, for instance independent iterations in loop, independent blocks of code which can be executed concurrently. Although OpenMP is not so flexible in comparison with other approaches but it is very easy to use.

To enable OpenMP you need to switch it on in the project properties, "C/C++/Language/OpenMP Support".

like image 8
sergtk Avatar answered Oct 17 '22 01:10

sergtk