Looking for a good site or book that explains windows threads, preferably for a beginner. Maybe has a example program to run, etc....
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With