473,486 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

max number of threads with linux 2.6 kernel

Don
Hi,

I'm trying to test out creating large numbers of threads
under the linux 2.6 kernel. I've written some code .. see below.
For some reason, I can't get to beyond about 4090 threads, even
when I set the per-thread stack size to be fairly small.
Am I bumping into a hard limit? Or, am I missing a configuration
somewhere that would allow me to get up to 10's of thousands
of threads?

The code I'm using is below. Any assistance would be appreciated,

Thanks,
Don

TestThread.H
==============

#ifndef TEST_THREAD_H
#define TEST_THREAD_H

#include <stdio.h>
#include <pthread.h>
class TestThread
{
public:
TestThread() {if (_mutex == NULL )
{
_mutex = new pthread_mutex_t;
pthread_mutex_init(_mutex,0);
}
}
~TestThread() {}
void start(int input_parameter);
static void *entryPoint(void *pthis);
void *run();
private:
int _input_parameter;
pthread_t _thread;
static pthread_mutex_t* _mutex;
};
#endif //TEST_THREAD_H

TestThread.C
================

#include "TestThread.H"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int STACKSIZE;

pthread_mutex_t* TestThread::_mutex = NULL;
void get_thread_stack_info();

int main(int argc, char **argv)
{
if(argc > 2)
STACKSIZE = 65536*atoi(argv[2]);
else
STACKSIZE = 65536*32;
get_thread_stack_info();
for ( int i = 0; i < atoi(argv[1]); i++)
{
TestThread tt;

printf("%i\n",i);
tt.start(i);
}
sleep(10);
}
void get_thread_stack_info()
{
size_t stacksize;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_getstacksize(&attr, &stacksize);
printf("default stacksize: %i\n",stacksize);
pthread_attr_setstacksize(&attr,STACKSIZE);
pthread_attr_getstacksize(&attr, &stacksize);
printf("new stacksize: %i\n",stacksize);
//printf("PTHREAD_STACK_SIZE: %i\n",PTHREAD_STACK_SIZE);
}

void *TestThread::run()
{
printf("GOT TO thread: %i\n", _input_parameter);
pthread_mutex_unlock(_mutex);
sleep(10);

return (void *)0;

}

void *TestThread::entryPoint(void *pthis)
{
//fprintf(stdout,"GOT TO entryPoint()\n");
TestThread *pt = (TestThread*)pthis;
pt->run();

return (void *)0;
}

void TestThread::start(int input_parameter)
{
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr,STACKSIZE);
pthread_mutex_lock(_mutex);
_input_parameter = input_parameter;
int ret = pthread_create( &_thread, &attr, TestThread::entryPoint, this);
printf("ret: %i : [%s]\n",ret, strerror(ret));

}

Jul 22 '05 #1
1 2565
"Don" <do*@nogarbageplease.cs.brown.edu> wrote...
I'm trying to test out creating large numbers of threads
under the linux 2.6 kernel. I've written some code .. [...]


Sorry, off-topic. Please ask in comp.os.linux.development.apps
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
30657
by: Tzach | last post by:
I'm developing a simple Java client that runs over a CORBA server. The main client thread is waiting for notification from this server. On each notification, The client creates a new thread...
3
5374
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
6
4539
by: Kirby Angell | last post by:
We are porting our applications from Python 2.2 on RH9 to Python 2.3 on RH9. One of our apps used to be able to create threads with wild abandon, 800 or more if necessary. With Python 2.3 we are...
3
1862
by: Maxwell Hammer | last post by:
An application I am developing executes many threads and then has a "monitor" part that waits for certain events. One of these events causes the application to have to shutdown. On shutdown the...
17
6383
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
8
2387
by: pavvka | last post by:
I'm making multithread server on Linux. Everything works fine, but server reaches threads limint and cannot create any one more. I've wrote simple test code to test this problem. #include...
12
18962
by: Paul Sijben | last post by:
I have a server in Python 2.5 that generates a lot of threads. It is running on a linux server (Fedora Core 6). The server quickly runs out of threads. I am seeing the following error. File...
6
2929
by: nikhilketkar | last post by:
What are the implications of the Global Interpreter Lock in Python ? Does this mean that Python threads cannot exploit a dual core processor and the only advantage of using threads is in that...
167
8143
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.