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?



I have 2 threads. One thread prints odd numbers and the second thread prints even numbers. Now, I h..

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

Post New Answer

More MFC Interview Questions

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

1 Answers   E Logic,


What is socket?

3 Answers  


how to give colour for dialog button or static buuto?any one explain full code ?pls pls

3 Answers  


What are the special requirements for dialog box resources used in a form view?

2 Answers  


Explain Doc/View architecture

6 Answers   Huawei,


What is Multithreading

1 Answers   Invensys,


What is a critical section and how is it implemented?

2 Answers  


What MFC base classes provide support for ActiveX controls?

2 Answers   Wipro,


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?

3 Answers   HP,


How can i implement the dynamic menus in MFC plz give the code

2 Answers  


Categories