 |
 |
posix thread question
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 1999
Location: mars,ca,usa
Status:
Offline
|
|
I've got a posix thread question.
How does one increase the maximum number of threads in a process?I think on 10.2 its limited to 255.(?) Grover needs more threads...
Is there a OS configuration tweak that I can do to increase the maximum number of threads for a single process?
Thanks for any suggestions.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status:
Offline
|
|
My guess is that this would be kernel level built into the code. I'd imagine that you could tweak the kernel code yourself and run a modified kernel, or you could recommend Apple increase it.
I do know that 255 threads is a VERY large number of threads to be running at once. Every single one of those threads has overhead to it. On a current Mac, the maximum possible number of threads to have running at once is TWO (Dual G4), so any sane coder would serialize their code in such a way that it would be reasonable. I think 255 threads is an unreasonable number to be running in a single program. Even most distributed apps running on a cluster of computers still wouldn't be running that many threads between ALL the computers.
What is this Grover you speak of? google didn't tell me anything.
|

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Ah crap... I meant to hit new post.
Anyway, grover was a loveable blue character on Sesame Street, right? What's he doing with all those threads?
Matt
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
What Deitrus said.
The overhead he speaks of consists of a stack and a copy of registers for each thread. I could be wrong, but I believe this memory is "wired", or always resident. Kernel memory is a precious resource. Don't abuse it.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 1999
Location: mars,ca,usa
Status:
Offline
|
|
Thanks for the suggestions. Actually, my bug situation is related to networking. I want to be able to handle many incomming connections. If you use select in a tcp server program then you are limited in the number of select bits you can use. So, I use accept. Spawning forked processes for each connection uses way more memory than threads. So, I chose to use threads. Which led me to the question about the number of threads.
I wrote a test program to test this. Actually, I can launch 500+ threads which is great. So, threads are not my issue. All is well in thread land.
My real issue is that accept is returning errno==EMFILE. I'm not sure on Mac OS X how to increase the maximum number of file descriptors. If I recall on linux its buried in the proc file system somewhere. This was actually my real problem and not the maximum number of threads. I think this is what was giving me that lower 255(?) number. linux has the same issue. Any suggestions on the EMFILE issue and OS X ?
Back to threads, if you run the following program it will bring down mac os 10.2 in a kernal panic. Yep, a cold reboot.
#include <iostream>
#include <pthread.h>
void entrypoint();
int main (int argc, const char * argv[]) {
int count = 0;
while(1) {
pthread_t thethread;
if( pthread_create( &thethread, NULL, (void *(*)(void *))&entrypoint, NULL ) != 0 ) {
}
else {
pthread_detach(thethread);
count++;
printf("count=%i\n",count);
}
// if( count == 500 ) { break; }
}
return 0;
}
//just stall out
void entrypoint() {
// printf("you are in the entry point.\n");
while(1) {
sleep(1);
}
}
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Feb 2000
Status:
Offline
|
|
erm... try a:
man sysctl
in a terminal window.
also try issuing a sysctl -a, as not all MIBs are documented.
...now you can use sysctl to "tune" (modify) a good deal of these parameters. I also wouldn't be surprised to find most/all of them buried in netinfo somewhere either.
(also works on Solaris, FreeBSD, NetBSD, OpenBSD, etc.)
don't bitch at me if you break something. You know the drill.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|