Linux - DistributionsThis forum is for Distribution specific questions.
Red Hat, Slackware, Debian, Novell, LFS, Mandriva, Ubuntu, Fedora - the list goes on and on...
Note: An (*) indicates there is no official participation from that distribution here at LQ.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
void run(void) {
char c;
if (i < 10)
printf("Address of c = %u KB\n", (unsigned int) &c / 1024);
sleep(60 * 60);
}
int main(int argc, char *argv[]) {
int rc = 0;
pthread_t thread[MAX_THREADS];
printf("Creating threads ...\n");
for (i = 0; i < MAX_THREADS && rc == 0; i++) {
rc = pthread_create(&(thread[i]), NULL, (void *) &run, NULL);
if (rc == 0) {
pthread_detach(thread[i]);
if ((i + 1) % 100 == 0)
printf("%i threads so far ...\n", i + 1);
}
else
printf("Failed with return code %i creating thread %i.\n",
rc, i + 1);
}
exit(0);
}
When i run this program i get the o/p as :
[root@ENTERPRIZE ashish]# ./thread-limit
Creating threads ...
Address of c = 3002970 KB
Address of c = 2992726 KB
Address of c = 2982482 KB
Address of c = 2972238 KB
Address of c = 2961994 KB
Address of c = 2951750 KB
Address of c = 2941506 KB
Address of c = 2931262 KB
Address of c = 2921018 KB
Address of c = 2910774 KB
100 threads so far ...
200 threads so far ...
300 threads so far ...
Failed with return code 12 creating thread 306.
[root@ENTERPRIZE ashish]#
Address of c = 1130590 KB
100 threads so far ...
200 threads so far ...
Failed with return code 12 creating thread 256.
Hey, at least you got a few more threads. I have a 2.6.5 kernel I compiled, however, my gcc/glib is from Fedora FC2/rpm'd in. I've tried playing with some of the things I found on the net, such as /etc/security/limits.conf and ulimit -u, but none of those work. I ran in to a problem once where I ran out of processes for something, so this has been one of those things that I've always had on the back burner to figure out.
But I am exiting every newly created thread soon after creation.
According to me, there should not be 381 threads running at the same time as all are exited very soon.
while(1)
{
...
//Create a new thread to echo the data to the same host
err = pthread_create( &thread_idd, NULL, transmit, rx );
perror("Threadcreate ");
}
}
void *transmit(packet *tx)
{
void *dummy;
// Transmit the received datagram to the same host
txcount = sendto( sd, (*tx).data, (*tx).count, 0, &((*tx).host),(*tx).len );
...
Even though we exit the thread, the threadi id is not released. Hence, if you are not waiting for the thread, use pthread_detach(tid) just after creating the thread. This will let you have as many threads as you want...
But I am exiting every newly created thread soon after creation.
According to me, there should not be 381 threads running at the same time as all are exited very soon.
while(1)
{
...
//Create a new thread to echo the data to the same host
err = pthread_create( &thread_idd, NULL, transmit, rx );
perror("Threadcreate ");
}
}
void *transmit(packet *tx)
{
void *dummy;
// Transmit the received datagram to the same host
txcount = sendto( sd, (*tx).data, (*tx).count, 0, &((*tx).host),(*tx).len );
...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.