Stack size for a thread

Ald aldarri_s at yahoo.com
Tue Jul 24 19:06:22 PDT 2007


So you are saying that the best I can do is to determine the size empirically
?
How platform-dependent would that be?  What does the stack frame format depend upon -- CPU, OS, language implementation?

With all the hype about Erlang I want to see how difficult would it be to implement asynchronous message passing between threads in D.  And besides, without shared data Erlang is simply not an option for what I have in mind.  
Imagine a hundred of moving objects, and each object needs to communicate with ten closest ones.  How does one find the closest ones?  Either sequential iteration through every object, with responses received if and when they are received, or a shared data structure, which in Erlang would be encapsulated in a process and create a bottleneck.

Sean Kelly Wrote:

> Ald wrote:
> > Hello.
> > 
> > As I have read in ths docs, Phobos' threads allow me to specify the stack size.
> > 
> > What is the default size?
> 
> I believe it's whatever the OS default is.
> 
> > Suppose I know the maximum amount of functions a thread stack at any single time along with the variables.  How to I calculate the stack size in bytes, and is it a good idea to begin with?
> 
> I'd say don't bother unless you're creating tons of threads and running 
> into memory problems as a result.  At that point, the easiest thing to 
> do would be just to print the address of local variables in the root and 
> the deepest thread function, do some subtraction, and fudge the number a 
> bit :p  Also, since stacks are allocated in increments of one page, for 
> most systems the stack you specify should generally be in multiples of 
> 4096 bytes.
> 
> 
> Sean



More information about the Digitalmars-d-learn mailing list