|
but how is it working for Integers?
V
|
|
|
|
|
Without the code I can only guess... So here is my best guess: Because the code to output the integers takes so fast that there is no context switch between the call.
John
|
|
|
|
|
if there is no context switch , it should print the same value right?.. sorry if i misunderstand, anyway plz view the code here.. plz try to help me . everytime i'm struggling with the threads .
char[4] agIndv;
UINT CQACDDlg::DevMonitoring(LPVOID p)
{
CQACDDlg * me = (CQACDDlg *)p;
me->DevMonitoring(agIndv);
return 0;
}
void CQACDDlg::DevMonitoring(char[] ageID)
{
while(1)
{
AfxMessageBox(ageID);
//Sleep here for a while
}
}
void CQACDDlg::OnSetSplit() // onclick for new Threads
{
m_SplitID.GetWindowText(agIndv,5); //agIndv is global taken from a CEdit box
AfxBeginThread(DevMonitoring,this);
}
in the header file,
i declare
static UINT DevMonitoring(LPVOID lp);
V
|
|
|
|
|
The objects passed to the threads should probably be allocated on the heap rather than the stack, and then destroyed by the secondary thread. Something like (in MFC):
CString *strName = new CString("David");
AfxBeginThread(ThreadProc, strName);
...
UINT ThreadProc( LPVOID lpVoid )
{
CString *str = (CString *) lpVoid;
...
delete *str;
return 0;
} The same concept can be used with non-MFC code.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
can you tell me in context with the below code?
char[4] agIndv;
UINT CQACDDlg::DevMonitoring(LPVOID p)
{
CQACDDlg * me = (CQACDDlg *)p;
me->DevMonitoring(agIndv);
return 0;
}
void CQACDDlg::DevMonitoring(char ageID[])
{
while(1)
{
AfxMessageBox(ageID);
}
}
void CQACDDlg::OnSetSplit() // OnClick for new Threads
{
m_SplitID.GetWindowText(agIndv,5); //agIndv is global taken from a CEdit box
AfxBeginThread(DevMonitoring,this);
}
Thanks
V
|
|
|
|
|
Hello,
If I see correct, you have a global instance of a char array. I guess that you use that array to write "TEST" and "CODE" to, that are passed to the thread.
Your problem is that you overwrite the contents of the array. So both threads are printing the same array!
To solve this problem, allocate a char array on the heap and pass that to the threads:
UINT CQACDDlg::DevMonitoring(LPVOID p)
{
CQACDDlg * me = (CQACDDlg *)p;
char* psAg = new char[];
me->DevMonitoring(psAg);
return 0;
}
void CQACDDlg::DevMonitoring(char* pszAgeID)
{
while(1)
AfxMessageBox(ageID);
delete[] pszAgeID;
}
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote:
Behind every great black man...
... is the police. - Conspiracy brother
Behind every great piece of code in this application is
......BOB and David- VivekUniq
EXCELLENT. thank u so much.
V
|
|
|
|
|
Vivekuniq wrote:
EXCELLENT. thank u so much.
You're welcome
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I'll try.
struct info
{
CQACDDlg *pThis;
char *string;
};
void CQACDDlg::DevMonitoring( LPSTR lp )
{
while (1)
AfxMessageBox(lp);
delete [] lp;
}
UINT DevMonitoring( LPVOID lpVoid )
{
struct info *me = (struct info *) lpVoid;
me->pThis->DevMonitoring(me->string);
delete me;
return 0;
}
void CQACDDlg::OnSetSplit()
{
struct info *s1 = new struct info;
s1->pThis = this;
s1->string = new char[5];
lstrcpy(s1->string, "CODE");
AfxBeginThread(::DevMonitoring, s1);
struct info *s2 = new struct info;
s2->pThis = this;
s2->string = new char[5];
lstrcpy(s2->string, "TEST");
AfxBeginThread(::DevMonitoring, s2);
}
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thank u so much man.. .. i'm so happy
V
|
|
|
|
|
Morning, all
Is it necessary to set the pointer to NULL after delete everytime in C++?
It would cause memory leak by just delete and NOT set to NULL, right?
Thank you!
|
|
|
|
|
valerie99 wrote:
Is it necessary to set the pointer to NULL after delete everytime in C++?
if you're about using the pointer variable again and want to be sure not to use an invalid memory block, yes, set to null.
valerie99 wrote:
it would cause memory leak by just delete and NOT set to NULL, right?
how ????
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
valerie99 wrote:
Is it necessary to set the pointer to NULL after delete everytime in C++?
It's not required, but it is recommended.
valerie99 wrote:
It would cause memory leak by just delete and NOT set to NULL, right?
No, not at all. The memory is freed within the delete operator. Setting the pointer to NULL afterwards is just a precautionary measure.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
valerie99 wrote:
Is it necessary to set the pointer to NULL after delete everytime in C++?
No, but it is considered "a good programming practice".
valerie99 wrote:
It would cause memory leak by just delete and NOT set to NULL, right?
No. It would not.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
valerie99 wrote:
It would cause memory leak by just delete and NOT set to NULL, right?
Out of curiosity, did you happen to program in a garbage collected environment?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
I'm using the COleDateTime control to allow the user to set the date.
My question is : How can i get the selected date by the user?
I know i should handle the MCN_SELECT message'but i don't know how to get the
selected date.
Anyone?
Regards,
Eli
|
|
|
|
|
eli15021979 wrote:
How can i get the selected date by the user?
By using any number of the Getxxx() methods:
GetMonth()
GetDay()
GetYear()
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi David,
First,Thanks for your prompt reply.
I tried the Getxxx() method but the give me the current system time and not the selected date.
Regards,
Eli
|
|
|
|
|
This makes no sense. A COleDateTime object represents whatever date you set it to, be it some past date, the current date, or some future date The concept of 'selecting' a date, much like you would with a UI component, does not exist. You can 'set' the date, however.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi David,
Thanks again for your answers.
It's my mistake - I've set the control class member to COleDateTime instead of CMonthCalCtrl.
with CMonthCalCtrl I can use the GetCurSel() to get the selected date.
With besr regards,
Eli
|
|
|
|
|
eli15021979 wrote:
with CMonthCalCtrl I can use the GetCurSel() to get the selected date.
Makes much more sense. Glad you are working now.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi all !
I have developed the application. in my main class, I call 8 thread . The main class must to wait all 8 Thread end to continute do something. How to known all 8 Thread ended ?
pls, help me !
Thank alots
|
|
|
|
|
You can use the WaitForMultipleObjects function using HANDLEs to your threads and setting bWaitAll to TRUE.
|
|
|
|
|
Take a look at WaitForSingleObject in the MSDN[^]
|
|
|
|
|
Don't you mean WaitForMultipleObjects() ?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|