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?
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 |
If application hangs while SendMessage is waiting for the result, how you handle it?
Hi can anyone explain about the synchronization objects types and where we are using in the code.
What is the use of CCmdTarget ?
What is the difference between hinsrtance and hprevinstance in WinMain function?
Explain StretchBlt and BitBlt
1)How to change the size of a button at run time ?
How to convert the content of buffer into lower case character.
19)how to set Back Ground Picture to a Dialog Box in MFC ?
What is the command routing in MFC framework?
what is the use of CCmdTarget?
What is the base class for MFC Framework ?
What is the initial function to be called in MFC and what it will do