- pthread allocates memory in a loop - at the same time fork is run in a loop - when this sample is compiled against uClibc 0.9.28 and run, it hangs (fork() does not return child) - by adding usleep(1) before p = malloc(1) helps. Any hints ? #include<unistd.h> #include<stdlib.h> #include<sys/types.h> #include<sys/wait.h> #include<pthread.h> void *run(void *foo) { int i, j, k; void *p; for (i = 0; i < 1000; i++) for (j = 0; j < 1000; j++) for (k = 0; k < 1000; k++) { p = malloc(1); free(p); } pthread_exit(NULL); } void main(void) { pthread_t thread; int i, pid, status; pthread_create(&thread, NULL, run, NULL); for (i = 0; i < 1000; i++) { pid = fork(); if (pid < 0) { printf("fork error\n"); break; } if (pid > 0) { printf("fork parent: %d\n", pid); wait(&status); } if (pid == 0) { printf("fork child: %d\n", getpid()); exit(0); } } exit(1); }
The same code works with uClibc-0.9.31 and LINUXTHREADS_NEW . Sometimes giving segmentation fault at the end of execution in _pthread_cleanup_push_defer.