Threads problem

I am having an estrange upper limit of maximum threads creation. I am using pthreads over kernel #1 SMP 2009-03-31 14:50:44 +0200 i686 i686 i386 GNU/Linux and when I reach the 300 simultaneous threads creation EAGAIN is returned by pthread_create().

I am sure that is not a resource lacking, the mem available is almost total and the processor is in idle state.

void *th(void *param)
	cout << *((int *)param) << endl;

int main()
        cout << sysconf( _SC_THREAD_THREADS_MAX ) << endl; //returns -1
		for(int i = 0; i < 1000; i++)
			int *no	= new int();
			*no		= i;
			(new Thread(th))->Start(no);
			//(new EventWaitHandler())->WaitOne(500);
	catch(Exception ex)
		cout << ex.getMessage() << endl;
	return 0;

Thread class constructor:

void Thread::Start(void* param)
		int returnValue	= 0;
		returnValue 	= pthread_create(_currentThreadID, NULL, _target, param);
		case EBUSY:
			throw ThreadException("Thread Creation Has Failed");
		case EINVAL:
			throw ThreadArgumentException("The Value Specified For The Argument Is Not Correct");
		case EAGAIN:
			throw ThreadException("Maximum Threads Creation Has Been Reached");

Please help.

hello? anybody?

> hello? anybody?

sometimes when you don’t get an answer it means no one knows the answer…

and, imho zero replies is a lot better than 1500 “no idea, sorry”


You’re probably running into the PTHREADS_THREADS_MAX limit. Unfortunately it requires a kernel recompile to increase.

more info (google cache)