Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any good beginner tutorials for threads in windows? C++ [closed]

Tags:

Looking for a good site or book that explains windows threads, preferably for a beginner. Maybe has a example program to run, etc....

like image 423
T.T.T. Avatar asked Mar 18 '09 17:03

T.T.T.


People also ask

Does thread work on Windows?

Microsoft Windows supports preemptive multitasking, which creates the effect of simultaneous execution of multiple threads from multiple processes. On a multiprocessor computer, the system can simultaneously execute as many threads as there are processors on the computer.

Does C have 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.

Which header file is required to implement threads in C language?

We must include the pthread. h header file at the beginning of the script to use all the functions of the pthreads library. To execute the c file, we have to use the -pthread or -lpthread in the command line while compiling the file.

How do you start a thread in C++?

To start a thread we simply need to create a new thread object and pass the executing code to be called (i.e, a callable object) into the constructor of the object. Once the object is created a new thread is launched which will execute the code specified in callable. After defining callable, pass it to the constructor.


1 Answers

You want Chapter 20 of Programming Windows by Charles Petzold "Multitasking and Multithreading".

It also covers related things like synchronization, and events.

This book is a classic, and probably one of the best ways to get a very good understanding of how Windows Win32 programming works with C++.

Otherwise you can start on this MSDN pages for CreateThread.

For a more portable solution, boost threads are another way to go as well. Combined with boost::bind and several boost synchronization objects, it makes for a very powerful threading library.

like image 150
Brian R. Bondy Avatar answered Sep 17 '22 22:09

Brian R. Bondy