View difference between Paste ID: UK1tfUSA and 8juxJv8T
SHOW: | | - or go back to the newest paste.
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);
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
}