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

General purpose classes in MFC

1 Answers   TCS,


2.create for 10 batch: Employee_Number Employee_name Employee_Dateofjoining Employee_address Employee_salary 1.select the employee name who deriving more than 10 thousand salary and joined before august 08. use structure and pointers

0 Answers   TCS,


What is difference between the TCP/IP and UDP socket

5 Answers   Invensys,


What is the difference between GetMessage and PeekMessage ?

3 Answers  


How to handle command line arguements from simple MFC application ?

2 Answers   TCS,






what do you mean by psychic window?

2 Answers   Patni,


how many types of classes are ther,what are that

7 Answers   L&T,


i have created runtime menu -- ( admistrator ->managepackage,manage module). but now i want to open a dialog when i select manage package and any other diaolg when selecting manage module ( whole selection is at run time only ) . Please HELP .its urgently required

3 Answers   Patni,


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

11 Answers   Infosys,


Types of DLL's

11 Answers   Invensys,


what message is sent to an application when the user presses the primary button?

0 Answers   University Exams,


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

0 Answers  


Categories