S
stephen
Hi
Just learning c and wonder if anyone can answer a question. I am
writing a program that uses threads. These threads will call a
specific function simultaneously. This specific function uses a global
pointer to run through a linked list of structures.
Thread1 enters the function and resets a global worker pointer to point
to the anchor of the linked list. It then continues to run through the
linked list. Meanwhile thread2 enters the function and resets the
global pointer to point to the anchor of the linked list. Am I to
understand that this will then cause problems with thread1 because it
is again pointing to the top of the linked list?
Now I have run into this problem I have gone away learnt threads (on
Windows, Red Hat and Solaris) and resolved the problem using both state
variables and mutexes (critical sections on Windows). Is there a
better and more simple way of doing this such as moving the global
pointer (the worker pointer that is not the anchor) into the function
itself? When threads enter the function are they still using the same
pointer or will each thread use a different copy>
I suppose the real question is when two threads call the same function
at the same time will they have there own copy of anylocal variables
within that function or do they still use the same copy of the local
variables?
Many thanks for everyones time!
Steve
Just learning c and wonder if anyone can answer a question. I am
writing a program that uses threads. These threads will call a
specific function simultaneously. This specific function uses a global
pointer to run through a linked list of structures.
Thread1 enters the function and resets a global worker pointer to point
to the anchor of the linked list. It then continues to run through the
linked list. Meanwhile thread2 enters the function and resets the
global pointer to point to the anchor of the linked list. Am I to
understand that this will then cause problems with thread1 because it
is again pointing to the top of the linked list?
Now I have run into this problem I have gone away learnt threads (on
Windows, Red Hat and Solaris) and resolved the problem using both state
variables and mutexes (critical sections on Windows). Is there a
better and more simple way of doing this such as moving the global
pointer (the worker pointer that is not the anchor) into the function
itself? When threads enter the function are they still using the same
pointer or will each thread use a different copy>
I suppose the real question is when two threads call the same function
at the same time will they have there own copy of anylocal variables
within that function or do they still use the same copy of the local
variables?
Many thanks for everyones time!
Steve