Subj : Re: regarding threads in VC++, for a beginnner To : comp.os.ms-windows.programmer.win32,comp.programming.threads From : David Schwartz Date : Tue Jan 25 2005 02:05 am "Ian T" wrote in message news:41f61690$0$14721$afc38c87@news.optusnet.com.au... > Scott McPhillips [MVP] wrote: >> If "space" means memory space: all threads in a process use the same >> memory space. If this were not so the void* thread parameter would be >> useless. > > Actually, sorry I was so imprecise. I was under the impression that each > thread has a stack and a "time slice". Yes and no about stacks. Since the stack is in the process' memory space, all threads share their staks in the sense that any thread could access any other thread's stack should it choose to do so. Each thread, however, has its own stack *pointer* which creates the illusion that the stack is local to the thread. However, a thread can legally pass another thread a pointer to a variable on its stack, so long as the other thread only uses that pointer while it remains valid. How threads are given CPU time can vary tremendoubly from operating system to operating system. Most allocate CPUs to threads that are avialable and pre-empt threads if a higher priority thread becomes ready to run. More than one thread may run at the same time on a machine with more than one logical CPU. > Does the member function use the thread's stack and run in it's "time > slice"? The new thread is allocated a new stack and set up however is needed for it to be scheduled. It's instruction pointer points at the entry point to the function you passed and its stack pointer points to the stack just allocated for it. The thread is made 'ready to run' (or suspended for functions that require you to manually start the thread). The schedule will then allocate the thread a time slice and it will begin executing the function in the context of that new thread. DS .