Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 24, 2007 Stack size for a thread | ||||
---|---|---|---|---|
| ||||
Hello. As I have read in ths docs, Phobos' threads allow me to specify the stack size. What is the default size? 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? |
July 25, 2007 Re: Stack size for a thread | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ald | 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 |
July 25, 2007 Re: Stack size for a thread | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | 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
|
July 25, 2007 Re: Stack size for a thread | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ald | If you wanna beat Erlang, os threads won't help, as I know Erlang uses some sort of internal threads mapped across os threads/cpus and even machines. something along the lines of CSP looks interesting enough, where you schedule stack threads and os threads smartly. take a look at DSCP from http://assertfalse.com/projects.shtml, it is a nice prototype implementation of CSP with some new ideas. Ald wrote: > 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 >> > > |
Copyright © 1999-2021 by the D Language Foundation