Subj : Re: stupid threading question .... To : comp.programming.threads From : David Schwartz Date : Mon Aug 15 2005 11:33 am "Daniel Rayment" wrote in message news:TYWdnbU705-2pp3eRVn-pg@rogers.com... > but how bout on a 2 or more processor machine? in the unlikely event that > 2 threads want to call the same function at the same time. (Once again > we are not talking about accessing data types or sharing global variable > or anything that "obviously is bad"). ssuppose the function that gets > called at the same time is Why would there be a problem? The function isn't changing, so two threads are just reading the same unchanging information. > function int doit(int &a, &b) > { > int c, d; > > c = a + b; > a = b *c; > d = c - a; > > if (a else return c > > } > > all variables are local or parameter reference. > > > thread::code() > { > static int (*func)(int &, int &)fn = doit; > > while (1) > { > WaitForSingleObject( whatever, INFINITE); > > int a, b; > (*fn)(a,b); > } > > } > > and of course under murphys law both wake at same time and call the > "doit" function supllyied as a pointer to func. So what do you think will go wrong? As you said, the variables are local. Even with one thread, there will need to be one copy for each invocation of the function. Consider: int fact(int i) { int j=i-1; if(i==00) return 1; return i * fact(j); } Clearly there has to be one 'j' for each invocation of this function, right? DS .