Maku Times
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.)

 
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

<< Home
Cut me... and I'll bleed Linux!






Name: makuchaku

Have a message?




Creator of the Linux Kernel

The man who started it all...
Hats off to you, Sir Torvalds!



My Piddi


Link IT Up Bloggers!
MakuChaku@Livejournal
Amritha
Saandu Bhai
AnkiPanki
HIM
D A Y A N I K A
Harpic
Manuj


I Support...
Get Firefox!   
My Browser

 Use OpenOffice.org
My Office App

My Distro


My Desktop

Powered by Blogger
My Blog


ARCHIVES
November 2004 / December 2004 / January 2005 / February 2005 / March 2005 / April 2005 / April 2007 /