Hi,
I have recently being learning and experimenting with pthread, and have noticed a weird behaviour (to me). I wrote a simple testing program to show my question:
the program, when run, terminates almost immediately, printing "382" on my Linux machine, apparently after hitting some limit. I expected it to run indefinitely because every thread created terminates itself. Can someone please enlighten me on this question?Code:#include <pthread.h> #include <iostream> void *doNothing(void *); int main () { pthread_t nothingThread; int count = 0; while (!(pthread_create(¬hingThread, NULL, doNothing, NULL))) { count++; usleep(1000); //so threads won't be created faster than they are terminated } std::cout << count << std::endl; } void *doNothing(void *) { pthread_exit(NULL); }
Thank you very much



LinkBack URL
About LinkBacks



