Subj : Re: a thread question To : comp.programming.threads From : David Schwartz Date : Thu May 12 2005 06:49 pm "Loic Domaigne" wrote in message news:3ehv4uF39d2dU1@individual.net... > Hi David, >>>>can I use it at the child thread? >>>To be visible from every threads, the variable must be global. >> Nope. All variables are visible to all threads. > Sure. But if count is declared in the main body, then the compiler shall > complain that count isn't defined if you refer to the count variable in > the thread (of course, you could always refer to count via its address). Exactly. You just can't refer to it quite as easily. > For the situation we're speaking of, I prefer to use a global variable. I can't imagine why you think that makes sense. Consider: void DoTwoJobs(void) { Job j, k; j->foo=x; j->bar=y; /* ... fill in the two jobs with what we want them to do */ DispatchThreadToDoJob(&j); DispatchThreadToDoJob(&k); /* here the two jobs are running in parallel */ j->WaitFor(); k->WaitFor(); } You would seriously argue that jobs 'j' and 'k' should be global? And what? We should have two separate 'DispatchThreadToDoJob' functions, one for job 'j' and one for job 'k'? Then what happens when some new piece of code needs three jobs? It is absolutely the most common thing in the world for threads to share non-global variables. DS .