Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Let's make a lot of threads!
// gcc -D_GNU_SOURCE=1 -std=c99 a.c
#include <sched.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int f(void *p) {
sleep(2);
}
void main(void) {
for(int i = 0; i < 32770; i++) {
void *s = malloc(256); // stack size
int r = clone(f, s, 0, NULL);
if(r < 0) {
printf("The number was: %d\n", i);
perror(NULL);
exit(0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.