Results 1 to 4 of 4

Thread: Threads problem

  1. #1
    Join Date
    Jun 2008
    Location
    As. - Paraguay - GMT -4
    Posts
    95

    Default Threads problem

    I am having an estrange upper limit of maximum threads creation. I am using pthreads over kernel
    2.6.27.21-0.1-pae #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.

    Code:
    void *th(void *param)
    {
    	cout << *((int *)param) << endl;
    }
    
    int main()
    {
            cout << sysconf( _SC_THREAD_THREADS_MAX ) << endl; //returns -1
    	try
    	{
    		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:
    Code:
    void Thread::Start(void* param)
    	{
    		int returnValue	= 0;
    		returnValue 	= pthread_create(_currentThreadID, NULL, _target, param);
    		switch(returnValue)
    		{
    		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.

  2. #2
    Join Date
    Jun 2008
    Location
    As. - Paraguay - GMT -4
    Posts
    95

    Default Re: Threads problem

    hello? anybody?

  3. #3
    brassy NNTP User

    Default Re: Threads problem

    > 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"

    --
    brassy

  4. #4
    Join Date
    Jun 2008
    Location
    Schenectady, NY
    Posts
    138

    Default Re: Threads problem

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

    more info (google cache)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •