[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

256 threads maximum?



Hi,

The following simple testprogram tries to create the number of threads given as argv[1].
When I'm using a 2.6.3 kernel with glibc 2.3.2/NPTL 0.60, the maximum number of threads this application can create is 255. With any number higher it complains about memory allocation failing.


./thrs 255
Creating 255 threads

./thrs 256
pthread_create problem: Cannot allocate memory
                                        ^^^ perror msg

When using LinuxThreads 0.10 on the same system, same binary it works just fine
LD_ASSUME_KERNEL=2.4.1 ./thrs 256
Creating 256 threads


For LinuxThreads the maximum number of threads appears to be 1532:
LD_ASSUME_KERNEL=2.4.1 ./thrs 1532
Creating 1532 threads

LD_ASSUME_KERNEL=2.4.1 ./thrs 1533
Creating 1532 threads
pthread_create problem: Success

Other then the strange error message, LinuxThreads seems to work.

What am I doing wrong? I know that NPTL can do a lot better then this, since I have been reading reports on NPTL creating thousands of threads ( I think I recall someone stating creating 300000 threads from one process). Where does the 255 limit come from?


Thanks for any reply.


With friendly regards,
Takis


#include <stdlib.h> #include <string.h> #include <stdio.h> #include <pthread.h> #include <unistd.h>

void* foo( void*p )
{
   return 0;
}

int main( int argc, char *argv[] )
{
   pthread_t * p;
   int i, nr = atoi( argv[ 1 ] );

p = ( pthread_t* ) calloc( nr, sizeof( pthread_t ) );
if ( p == NULL )
{
perror( "not enough mem for allocating thread structs in userspace" );
exit( 1 );
}


   printf( "Creating %d threads\n", nr );
   for ( i = 0; i < nr; i++ )
       if ( pthread_create( &p[ i ], 0, foo, 0 ) != 0 )
       {
           perror( "pthread_create problem" );
           exit( 1 );
       }
   for ( i = 0; i < nr; i++ )
       if ( p[ i ] != 0 )
           pthread_join( p[ i ], 0 );
   return 0;
}



With friendly regards,
Takis




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]