3 ms·
C implementation for Windows: #include <stdio.h> #include <windows.h> #include <process.h> void sleep_on_it(void* param) { int n = *(int*)pa
by bluecalm 12y ago
C implementation for Windows:
#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);
}
Compile with gcc -std=c99 (because of VLA's it won't work in Visual Studio).
Example:
D:>sleepsort 1000 9 2 150 1 7 17 624
1 2 7 9 17 150 624 1000