Consider this piece of code here, where I am trying to create a bunch of threads that end up processing a task that mimics a race condition.
const int thread_count = 128;
pthread_t threads[thread_count];
for (int n = 0; n != thread_count; ++n)
{
ret = pthread_create(&threads[n], 0, test_thread_fun, &test_thread_args);
if( ret != 0 )
{
fprintf( stdout, "Fail %d %d", ret, errno );
exit(0);
}
}
Things usually work fine, except that sometimes pthread_create fails with the errno EAGAIN resource, which is temporarily unavailable, I tried to get to sleep and try to create, but without real effect.
failure is sporadic, and on some boxes there are no failures, and on some it happens very often.
any idea what might be wrong here?
Change - 1
update max-threads
cat /proc/sys/kernel/threads-max
256467
Edit 2
I think the inputs here made me think, I will probably do lower and post any results that are worth sharing.
- , , thread_function .
- ( )
- script, , / , , , , .
- , , .