Multithreading Local Variables
-
In a multithreading application I was wondering if I need to worry about 2 seperate threads overwriting each other's local variables. In other words if 2 seperate threads called the same function at the same time would the compiled program in essence create 2 sets of local variables, one for each thread, or is there a risk that they could overwrite each others data? Thanks for your help, Mike
-
In a multithreading application I was wondering if I need to worry about 2 seperate threads overwriting each other's local variables. In other words if 2 seperate threads called the same function at the same time would the compiled program in essence create 2 sets of local variables, one for each thread, or is there a risk that they could overwrite each others data? Thanks for your help, Mike
MikeMarq wrote:
if 2 seperate threads called the same function at the same time would the compiled program in essence create 2 sets of local variables, one for each thread
Yes. For more on this, check out a discussion[^] I had with someone on the C# message board.
-
MikeMarq wrote:
if 2 seperate threads called the same function at the same time would the compiled program in essence create 2 sets of local variables, one for each thread
Yes. For more on this, check out a discussion[^] I had with someone on the C# message board.
-
In a multithreading application I was wondering if I need to worry about 2 seperate threads overwriting each other's local variables. In other words if 2 seperate threads called the same function at the same time would the compiled program in essence create 2 sets of local variables, one for each thread, or is there a risk that they could overwrite each others data? Thanks for your help, Mike
Read about synclock and monitor. They provide a mechanism that locks an object and blocks other threads from accessing it except the thread that created the lock. When the lock is released the blocked threads are allowed similar lock and access.