Results 1 to 2 of 2
How are stack addresses possible at multi-threads application?
A typical method for creating a single thread is something like this:
---------------------------------------------------------
pthread_attr_t atr;
pthread_attr_init(&atr);
pthread_create(&thread, &atr, &func, NULL);
---------------------------------------------------------
pthread_attr_init() ...
- 02-16-2009 #1Just Joined!
- Join Date
- Feb 2009
- Location
- Japan
- Posts
- 2
setting stack addresses for muli-threads creation
How are stack addresses possible at multi-threads application?
A typical method for creating a single thread is something like this:
---------------------------------------------------------
pthread_attr_t atr;
pthread_attr_init(&atr);
pthread_create(&thread, &atr, &func, NULL);
---------------------------------------------------------
pthread_attr_init() always initiates a stack address at the fixed value. This is functioning well if just creating a single thread in a single process like above. The stack memory starts with the same address that pthread_create() allocates automatically without coder's any attention.
And then, how are stack addresses possible in case of creating many threads in a single process? If just repeating a chain of combined cycle of pthread_attr_init() and pthread_create(), I guess that every stack addresses might be allocated at the same place of memory by the reason from the single thread application.
My question focuses on this occasion:
1. What would be happned when repeating pthread_create() without stack address changes. Do every threads work accurately around a common stack range of memory, or some unexpected events might be happend by a kind of memory confliction?
2. If some wrong result comes with a operation above, how is it possible to avoid this problem? My idea is that every threads has to be set personal stack address and size by pthread_attr_setstackaddr() and pthread_attr_setstacksize() before pthread_create(). For sure that it is required to design well of stack memory map to have no memory confliction. Is this correct?
- 02-16-2009 #2
You should read up virtual memory and processes...it will clear up any questions you have on stacks and processes..Hope this helps Gerard4143
Welcome to the forums


Reply With Quote