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 |
What is the difference between the Encapsulation and Abstraction
25 Answers HCL, Invensys, TCS, Wipro,
is it possible to display a window .without using windowclass
What is socket?
how to give colour for dialog button or static buuto?any one explain full code ?pls pls
What are the special requirements for dialog box resources used in a form view?
Explain Doc/View architecture
What is Multithreading
What is a critical section and how is it implemented?
What MFC base classes provide support for ActiveX controls?
what is the difference between SDI and MDI
15 Answers CMC, HCL, Siemens,
How can update edit control data of an executing application from other application?
How can i implement the dynamic menus in MFC plz give the code