473,609 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with threads limit.

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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

using namespace std;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_I NITIALIZER;
int counter = 0;

void *print_message_ function( void *ptr )
{
char *message;
message = (char *) ptr;
pthread_mutex_l ock( &mutex1 );
counter++;
int nr = counter;
printf("Thread ID: %d \n", nr);
pthread_mutex_u nlock( &mutex1 );
}

main()
{
char *message1 = "Thread";
int iret1;

for (int i = 0; i < 400; i++)
{
pthread_t *thread1 = new pthread_t;

if (iret1 = pthread_create( thread1, NULL,
print_message_f unction, (void *) message1))
{
printf("Thread creation failed: %d\n", iret1);
}
}

exit(0);
}

Got results like this:

pawka@pawka-desktop:~/Darbai$ g++ -lpthread test.cpp -o test
pawka@pawka-desktop:~/Darbai$ ./test
Thread ID: 1
Thread ID: 2
Thread ID: 3
<...>
Thread ID: 378
Thread ID: 379
Thread ID: 380
Thread creation failed: 12
Thread creation failed: 12
Thread creation failed: 12
<...>

Every time around 380 thread my program fails creating threads. How fix
it?

Aug 1 '06 #1
8 2397

pa****@gmail.co m wrote:
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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

using namespace std;

[snip]
>
Every time around 380 thread my program fails creating threads. How fix
it?
You need to redesign your application. 380 threads is just plain silly
unless you have at least 100 physical processors.

/Peter

Aug 1 '06 #2
pa****@gmail.co m wrote:
I'm making multithread server on Linux.
This is off-topic here. Please ask your question in a Linux programming
newsgroup.

Aug 1 '06 #3
pa****@gmail.co m wrote:
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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

using namespace std;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_I NITIALIZER;
int counter = 0;

void *print_message_ function( void *ptr )
{
char *message;
message = (char *) ptr;
pthread_mutex_l ock( &mutex1 );
counter++;
int nr = counter;
printf("Thread ID: %d \n", nr);
pthread_mutex_u nlock( &mutex1 );
}

main()
{
char *message1 = "Thread";
int iret1;

for (int i = 0; i < 400; i++)
{
pthread_t *thread1 = new pthread_t;

if (iret1 = pthread_create( thread1, NULL,
print_message_f unction, (void *) message1))
{
printf("Thread creation failed: %d\n", iret1);
}
}

exit(0);
}

Got results like this:

pawka@pawka-desktop:~/Darbai$ g++ -lpthread test.cpp -o test
pawka@pawka-desktop:~/Darbai$ ./test
Thread ID: 1
Thread ID: 2
Thread ID: 3
<...>
Thread ID: 378
Thread ID: 379
Thread ID: 380
Thread creation failed: 12
Thread creation failed: 12
Thread creation failed: 12
<...>

Every time around 380 thread my program fails creating threads. How fix
it?
Your question is off-topic for comp.lang.c++, follow-ups set to
comp.os.linux.d evelopment.

As for your question, I think probably you need to look up the man page
for pthread_join.

--
Alan Johnson
Aug 1 '06 #4
pa****@gmail.co m wrote:
>
Every time around 380 thread my program fails creating threads. How fix
it?
Linux doesn't run on anything big enough to justify 380 threads!
Rethink your design and ask on a Linux group when you do.

--
Ian Collins.
Aug 1 '06 #5
Ian Collins wrote:
pa****@gmail.co m wrote:
>>
Every time around 380 thread my program fails creating threads. How fix
it?
Linux doesn't run on anything big enough to justify 380 threads!
Well... it runs on mainframes with thousands of CPUs. But I doubt the OP is
using one of those.

Aug 1 '06 #6
pa****@gmail.co m wrote:
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.
Your sample code shows nothing because you are creating joinable
threads and not calling pthread_join on them. A joinable thread
continues to occupy resources until it is joined. Those resources may
stand in the way of being able to create threads.

A reasonable server only has enough threads to keep all of the CPU's
busy. Usually, the number of threads to achieve that is some small
number, greater than one, multiplied by the number of available CPU's.
In a very compute-intensive application, that multiple tends to be
smaller. If there is a lot of blocking I/O, the factor is larger.

Aug 1 '06 #7
Rolf Magnus wrote:
Ian Collins wrote:

>>pa****@gmail. com wrote:
>>>Every time around 380 thread my program fails creating threads. How fix
it?

Linux doesn't run on anything big enough to justify 380 threads!


Well... it runs on mainframes with thousands of CPUs. But I doubt the OP is
using one of those.
With a single kernel instance?

--
Ian Collins.
Aug 2 '06 #8
VL
Ian Collins wrote:
>>>Linux doesn't run on anything big enough to justify 380 threads!


Well... it runs on mainframes with thousands of CPUs. But I doubt the OP
is using one of those.
With a single kernel instance?
I did not hear of "thousands" of CPUs, but 1024 CPUs is possible, I think:
http://www.sgi.com/company_info/news...altix4700.html

Quoted from the PR:
"On its powerful and acclaimed SGI® Altix® 4700 blade platform and a beta
version of SUSE® Linux Enterprise Server 10 from Novell, SGI demonstrated a
single system image (SSI) running on a world-record 1,024 processors."

I do not know if "single system image" means the same as your term "single
kernel instance", but it sounds likely to me.
Aug 2 '06 #9

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

Similar topics

1
2935
by: rbt | last post by:
This may be a stupid question, but here goes: When designing a threaded application, is there a pratical limit on the number of threads that one should use or is there a way to set it up so that the OS handles the number of threads automatically? I am developing on 32-bit x86 Intel systems with python 2.4.1. The OS will be Linux and Windows. I have an older app that used to work fine (254 threads) on early 2.3 Pythons, but now, I get...
3
4365
by: zeedan | last post by:
Hi, I appologise if I'm not posting this to the correct group, but I'm having problems starting MySQL server. I need it in order to post a websurvey for a research project I'm doing for a college computer ethics class. Well here is the output several commands, from netstat -a I can see that MySQL is listening, but when I try to start the server I get a port error. I'm running SUSE 9.1 and I searched all over the web for info on this...
31
2480
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not tipical) from the Internet and doing some processing on those would be considered to be a big/long task for a thread from a pool. In our app it is possible to break the task into some small ones (thread per fetch and processing thereafter or event...
0
1363
by: John Knaack | last post by:
I'm currently having problems setting up the max concurrent user allowed to a server with a web service. I have a asmx file that basically makes sql calls to a database and generates a XML file and sends it back to the user. The user can select multiple items at once. For each that they selected, a new thread is created and makes a call to the asmx file. The first problem I had was that only two threads where running at any given time. If...
5
4819
by: Marty McDonald | last post by:
I create and start several threads, each thread executes the same method - within the method, a web service is invoked. I find that the more threads I use, the longer it takes for all of the threads to finish. The threads are asynchronous, correct? And I thought each would be able to use it's own version of the web service. Am I wrong, does the web service force only one thread at a time to execute? Here is code if interested... I'm...
7
1948
by: mircu | last post by:
Hello, What would be the best for implementing architecture that runs several, independent, scheduled or run by the user on demand task in the same time? Now in my program every task creates it's own thread and run in it and after it completes the thread is destroyed automatically by the framework. So it is the simplest solution and I think it can be done better.
3
2490
by: GroupReader | last post by:
Each .net app, by default, has 25 threads (per processor) in the threadpool, right? ... but when calling ThreadStart, I'm creating a new thread and not using the threadpool, right? I don't want to get into any lengthy discussion about the best-practices and the best use of threads etc... I'm asking this question just to satisfy my own curiosity: On a typical windows server computer (Win2000 server or Win2003 server), how many...
35
9326
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
6
1343
by: rh0dium | last post by:
Hi Experts!! I am trying to get the following little snippet to push my data to the function func(). What I would expect to happen is it to print out the contents of a and loglevel. But it's not working. Can someone please help me out. ---------<snip>-------------- #!/usr/bin/env python
0
8145
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8095
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8556
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8410
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5526
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4037
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2541
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 we have to send another system
1
1690
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.