Advertisement
Guest User

Simple threading example in Win32

a guest
Jan 26th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. int thread(int num) {
  6.     Sleep(rand()%10000);                   // Sleep randomly between 0 and 10 seconds
  7.     printf("Thread %d finished\n",num);    // Print and exit
  8. }
  9.  
  10. int main(int argc,char** argv) {
  11.     int i=0;
  12.     for (i=0; i<10; i++) {
  13.         CreateThread(NULL,0,thread,{i},0); // Create the thread, notice that this will happen instantly
  14.     }
  15.     Sleep(15000);                          // Give the processes time to finish
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement