Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


I have 2 threads. One thread prints odd numbers and the
second thread prints even numbers. Now, I have to execute
the threads alternatively so that i can output 1,2,3,4,5,6,.....
write code for this?



I have 2 threads. One thread prints odd numbers and the second thread prints even numbers. Now, I h..

Answer / bala narasimha reddy

Static nNum = 1;
CEvent cs(False, False);

AfxBeginThread(PrintOdd, 0);
AfxBeginThread(PrintEven, 0);



Void PrintOdd(LPVOID pParam)
{
CString str;
while( s <= MAXNUM)
{
cs.lock();
str.Format("%d",nNum);
nNum ++;
outputdebugstring(str);
cs.setEvent();
}
}

Void PrintEven(LPVOID pParam)
{
CString str;
while( s <= MAXNUM)
{
cs.lock();
str.Format("%d",nNum);
nNum ++;
outputdebugstring(str);
cs.setEvent();
}
}

Is This Answer Correct ?    5 Yes 7 No

Post New Answer

More MFC Interview Questions

How to find the mouse entering an image?..while entering need to display next image...

4 Answers  


Explain the flow of SDI application?

8 Answers   Mphasis,


1)dynamic creation of a Button ?

2 Answers   TCS,


In SDI how many view's are attached to document object and in MDI how many view's are attached to Document object?

2 Answers   Wipro,


What is the difference between Synchronous sockets and asynchronous sockets?

2 Answers  


How to handle command line arguements from simple MFC application ?

2 Answers   TCS,


Difference between Debug and Release versions?

4 Answers  


19)how to set Back Ground Picture to a Dialog Box in MFC ?

1 Answers  


What is Thread ?(VC++)What is the difference between Cmutex and Csemaphone?

5 Answers   Atos Origin,


What function is used to disable a control at runtime?

7 Answers  


is it possible to display a window .without using windowclass

1 Answers   E Logic,


What is primitive and non-primitive application?

2 Answers   HCL,


Categories