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 |
How to find the mouse entering an image?..while entering need to display next image...
Explain the flow of SDI application?
1)dynamic creation of a Button ?
In SDI how many view's are attached to document object and in MDI how many view's are attached to Document object?
What is the difference between Synchronous sockets and asynchronous sockets?
How to handle command line arguements from simple MFC application ?
Difference between Debug and Release versions?
19)how to set Back Ground Picture to a Dialog Box in MFC ?
What is Thread ?(VC++)What is the difference between Cmutex and Csemaphone?
What function is used to disable a control at runtime?
is it possible to display a window .without using windowclass
What is primitive and non-primitive application?