#include <stdio.h> #include <windows.h> #include <process.h> void sleep_on_it(void* param) { int n = *(int*)param; Sleep(n); printf("%d ", n); } int main(int argc, char **argv) { int ar[argc]; HANDLE threads[argc-1]; for (int i = 1; i < argc; i++){ ar[i] = atoi(argv[i]); threads[i-1] = (HANDLE)_beginthread(&sleep_on_it, 0, &(ar[i])); } WaitForMultipleObjects(argc-1, threads, TRUE, INFINITE); }
Example:
D:>sleepsort 1000 9 2 150 1 7 17 624
1 2 7 9 17 150 624 1000
Example:
D:>sleepsort 1000 9 2 150 1 7 17 624
1 2 7 9 17 150 624 1000