Thursday, April 21, 2005
This will THREAD your brains
An interesting question...
Consider a function PlusPlus()
static int i;
void PlusPlus()
{
i++;
}
Now 2 threads are created...
THREAD 1
PlusPlus();
PlusPlus();
PlusPlus();
THREAD 2
PlusPlus();
PlusPlus();
PlusPlus();
PlusPlus();
PlusPlus();
Assuming that all necessary work is done to set up these threads & PlusPlus function, what will be the MAX & MIN value of "i" after the threads stop executing. Support your answers with some explanations.
ASSUMPTIONS
1. The system scheduler follows random scheduling algorithm
2. Thread 1 or Thread 2, either can be executed first (because of 1st assumpt.)
Subscribe to:
Post Comments (Atom)
6 comments:
minimum ---- 0
maximum ----8
waise when u r going to give answer of this????
maku courier kiya kya
Reading about threads...
Will try this problem 2moro & post the results here.
As of now, even i cannot tell the answer.
maku courier kar de na
plssssssssssssssssssss
i think its :
min. 3 and max. 8.......
I gave same answer as HP.
Lets see whats the actual answer :-)
Post a Comment