July 2017
Intermediate to advanced
244 pages
6h 33m
English
A basic example of using Windows threads, as adapted from the official MSDN documentation sample code, looks like this:
#include <windows.h> #include <tchar.h> #include <strsafe.h> #define MAX_THREADS 3 #define BUF_SIZE 255
After including a series of Windows-specific headers for the thread functions, character strings, and more, we define the number of threads we wish to create as well as the size of the message buffer in the Worker function.
We also define a struct type (passed by void pointer: LPVOID) to contain the sample data we pass to each worker thread:
typedef struct MyData { int val1; int val2; } MYDATA, *PMYDATA;DWORD WINAPI worker(LPVOID lpParam) { HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); if ...Read now
Unlock full access