Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about Threads

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
Okay, lets say I have a ThreadProc that I have defined and I start that thread...now, when a certain event happens in the thread, I start another one with the same ThreadProc. So in essence, I have two threads running that are using the same ThreadProc. Now, my question is this, even though they are the same function, they are different threads and therefore run in seperate memory spaces. The variables defined in my ThreadProc will be seperate no matter how many threads of the same ThreadProc are ran...so, the variables (eventhough they have the same name) will operate in a different memory space and not interfere with each other. I just need someone to confirm my thoughts. Thanks in advance guys!

Niky Williams
Lead Engineer
NTS Marketing, Inc.
 
Different threads in a single process run in the same address space. So, if you have a global variable, it is the same for both the threads. A local variable declared in one of the thread's functions is placed on the stack. Each thread has its own stack, so they are not the same for both threads.

Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top