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 |
I want recent paper pattern for HP company?
Tell me about different kinds of synchranization objects ?
What is the difference between GetMessage and PeekMessage ?
what is the use of Mutex and critical section
How to update windows title bar dynamically?
how does conditionally close the Dialog Box ?
What is a message map?
How to update all the views whenver document got updated ?
What is the difference between the SDI and MDI
what is the component of CLR ?
what is the updated verssion in vc++
Difference between Debug and Release versions?