The basic idea is you call CreateThread() and pass it a pointer to your thread function, which is what will be run on the target thread once it is created. The simplest code to do it is: #include <windows. h> DWORD WINAPI ThreadFunc(void* data) { // Do stuff.
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.
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.
To create a thread, the Windows API supplies the CreateThread( ) function. Each thread has its own stack (see thread vs processes). You can specify the size of the new thread's stack in bytes using the stackSize parameter which is the 2nd argument of CreateThread( ) function in the example below.
What do I need and how can I use threads in C on Windows Vista?
Could you please give me a simple code example?
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