Multithreading, gerneral question

Hello everybody,

i have a general question:

If i have a process and within i create a thread, in which a function "whatever" runs ... can the function then recognize changes to a variable that is existing within the main process and if yes, how ?
Has it to be global, for instance, or do i have to pass a pointer or what do i have to do so far ?
It can't be that i'd have to use a pipe or other IPC, for then "Multithreading" would not be much different from "Multiprocessing", or ?

I'm definitly new to such issues, as you see.

Thanks in advance,
The answer is sort of. If a variable is modified, as long as both threads have some way of accessing it, then the function in the secondary thread will continue to act as if there is a change. This could be from it being a global variable, but it can also be through a pointer passed (if you think about it, the address space pointed to is what is being modified). Of course, you have to be careful and lock your threads and that variable accordingly using mutex's and the like, otherwise there could be problems like trying to write two things at once, or reading it as it is being written, or other complicated synchronization issues like that.
can the [thread] function then recognize changes to a variable that is existing within the main process and if yes, how ?

There is a special provision for threads in some environments where they can have access to their own data, this is called thread local storage (TLS).

Ignoring TLS, threads have equal access to all the stuff that the main thread has access to. That's why synchronised access is required.
Thanks for the answer.
I am sure i'll be back with some questions concering synchronization issues soon.
However that helped me yet, thanks again.

Greetings,
fluppe
Topic archived. No new replies allowed.