segfault with clone() and printf
问题 I'm trying to experiment with how clone() is implemented for threads in Linux 3.10.0-327.3.1.el7.x86_64 I'm running this piece of code and having occasional segfaults. I know if I use CLONE_THREAD then there's no way to check if the thread finished, but why does printf cause problems? How does the Pthread library handle this issue? Without the printf s there's no segfault. #define STACK_SIZE (1ULL<<22) //4MB int tmp = 10; int threadfunc(void *ptr) { printf("i'm here\n"); tmp++; return 0; }