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 |
Given two processes, how can they share memory?
Explain in sort What is CTargetObject?
what is the difference between compiling and building?
What?s the difference between Modal and Modeless Dialog?
What is the range of intensity of RGB
What is a critical section and how is it implemented?
What is the difference between GetMessage and PeekMessage ?
What are the special requirements for dialog box resources used in a form view?
What is CSingleDocTemplate?
I want recent paper pattern for HP company?
what is the use of Mutex and critical section
How do I create a dialog box in mfc?