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

If application hangs while SendMessage is waiting for the result, how you handle it?

2 Answers  


Hi can anyone explain about the synchronization objects types and where we are using in the code.

1 Answers  


What is the use of CCmdTarget ?

4 Answers  


What is the difference between hinsrtance and hprevinstance in WinMain function?

3 Answers  


Explain StretchBlt and BitBlt

1 Answers  






1)How to change the size of a button at run time ?

1 Answers  


How to convert the content of buffer into lower case character.

3 Answers   E Logic,


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

1 Answers  


What is the command routing in MFC framework?

3 Answers  


what is the use of CCmdTarget?

4 Answers   Siemens,


What is the base class for MFC Framework ?

4 Answers  


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

11 Answers   Infosys,


Categories