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 initial function to be called in MFC and what it will do
visual Pogramming c++ coding for create a paint application.. (Please someone help me)
if both base and derived class have the constructors if i create an object for derive class which class constructor is executed first
How do you change the properties for a tree view control that is part of the CTreeView class?
If i derive a new class from CObject what are the basic features my derived wil get ?
what if we provide two message handler for same message ?
what is the meaning of constant FILE EXCEEDS LENGTH LIMIT while loading from ps file to vsam in the jcl?
1)How to change a text of a button in runtime?
1)How to change a text of a button as Dynamically?
Difference between Cclint DC & Cpaint Dc
How you create a button dynamically?
What is a critical section and how is it implemented?