Skip to content

Instantly share code, notes, and snippets.

@insom
Created May 8, 2017 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insom/7f60e9bb55c287e514228b0b18e530da to your computer and use it in GitHub Desktop.
Save insom/7f60e9bb55c287e514228b0b18e530da to your computer and use it in GitHub Desktop.
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