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

What is the initial function to be called in MFC and what it will do

11 Answers   Infosys,


visual Pogramming c++ coding for create a paint application.. (Please someone help me)

2 Answers  


if both base and derived class have the constructors if i create an object for derive class which class constructor is executed first

10 Answers   Siemens, Symphony,


How do you change the properties for a tree view control that is part of the CTreeView class?

1 Answers  


If i derive a new class from CObject what are the basic features my derived wil get ?

4 Answers   Microsoft,


what if we provide two message handler for same message ?

1 Answers  


what is the meaning of constant FILE EXCEEDS LENGTH LIMIT while loading from ps file to vsam in the jcl?

0 Answers  


1)How to change a text of a button in runtime?

2 Answers  


1)How to change a text of a button as Dynamically?

1 Answers   HCL,


Difference between Cclint DC & Cpaint Dc

6 Answers   E Logic,


How you create a button dynamically?

2 Answers  


What is a critical section and how is it implemented?

2 Answers  


Categories