Andrew

Andrew

  • NA
  • 3
  • 0

question from interview

May 6 2009 4:13 AM
Hi all
it's my first time here and here's a question that I was asked yesterday
it's kind of pseudocode

____________________________________________
int globalVar = 0;
void Func() {
for (int i = 0; i < 10; i++)
globalVar = globalVar + 1;
}

void main() {
Thread x = new Thread(Func); x.Start();
Thread y = new Thread(Func); y.Start();
x.Join();
y.Join();

Write(globalVar);
}
____________________________________________

the final globalVar has values from 1 to 20.
I understand how it can be from 10 to 20, but
can you explain how can it be less than 10?

thanks

Answers (2)