#define MAX_THREADS ... ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:#define MAX_THREADS ... ?

Post by Candy »

Guest wrote: I'ld recommend what solar told you.
For examples bsd* uses a sysctl() to set & get this value
Linux also uses the same, but for threads & process linux doesn't have a maximum limit, the max limit is your memory.
Thanks
A limit is defined as, if all other is unlimited, what would this maximum be.

Linux has a 16 bit pid. They cannot create more than 65535 processes in any case, ever. AFAIK each thread also uses a pid, so that would limit the number of threads to 65535 as well.
FlashBurn

Re:#define MAX_THREADS ... ?

Post by FlashBurn »

I have the following limits and I think they are enough (i also like only to learn from my os, because when I have a 64bit machine I will rewrite it for 64bit and then there wont be such limits).

Code: Select all

4096 processes
65536 threads
65536 ports
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:#define MAX_THREADS ... ?

Post by Pype.Clicker »

indeed, linux uses the PID for threads identification, and yes, it would be typical to use a "factory" pattern in those cases. And yes, using 16 bits as PID is very convenient for the OS designer as it means a flat table of process pointers can safely be envisionned (yes, we're locking 256 KB for the process table, sue us).

yet, iirc, there are patches that allow 32-bit pids, right ?

Code: Select all

// out of linux/threads.h ...
/*
 * This controls the default maximum pid allocated to a process
 */
#define PID_MAX_DEFAULT 0x8000

/*
 * A maximum of 4 million PIDs should be enough for a while:
 */
#define PID_MAX_LIMIT (sizeof(long) > 4 ? 4*1024*1024 : PID_MAX_DEFAULT)
Post Reply