-
August 10th, 2005, 02:43 PM
#1
Threads have sequential behavior
Hi,
I have an ATL service(..COINIT_MULTITHREADED) and i include a function which has a loop and create 2 threads ..make some things more and release them..i used CreateThread and waitformutlipleobjects but this code just works in the first loop ..after that i can realize the processing is sequential and even if i try to stop debbuging it tries to debug MSDEV. exe in other VC and throws an exeption..which close both VStudios..here i put my code:
CServiceModuleRun()
{
..
Funcion()....
..
}
void Funcion()
while(loop)
{
phThread = new HANDLE[2];
//if(phThread[0]==NULL)
phThread[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Login, NULL, 0, &idThread);
//if(phThread[1]==NULL)
phThread[1] = CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Locales, NULL, 0, &idThread);
WaitForMultipleObjects(2,phThread,true,INFINITE);
GetExitCodeThread(phThread[0], &nRows);
CloseHandle(phThread[0]);
GetExitCodeThread(phThread[1], &nRows);
CloseHandle(phThread[1]);
delete []phThread ;
...
...
}
And i realized about the trace output repeat the thread Id in each iteration..
What i am not considering...
Thanks in advance and 4 the patience...
-
August 10th, 2005, 04:06 PM
#2
Re: Threads have sequential behavior
What value does WaitForMultipleObjects return?
What values do the GetExitCodeThread calls return?
Also you should pass TRUE, not true for the third parameter.
The type is BOOL not bool (BOOL is a windows type, bool is C++)
Last edited by Dave McLelland; August 10th, 2005 at 05:22 PM.
Dave Mclelland.
-
August 11th, 2005, 11:00 AM
#3
Re: Threads have sequential behavior
WEll WaitforMultipleObjects everytime returns 0 and the threads in trace say that has excited with code -858993460 (0xCCCCCCCC).
my ThreadFunctions looks like this:
void Login(void *a)
{
try{
unsigned int retcode;
_Module.PendientesLoginX->RevisaBD();
CloseHandle(phThread[0]);
ExitThread(retcode);
phThread[0] = NULL;
}
catch(...)
{
}
}
Really i am new in this subject..and i d apreciate any help in the structure of this multithreading..
Thanks 4 patience..
-
August 11th, 2005, 03:18 PM
#4
Re: Threads have sequential behavior
Try removing the
Code:
CloseHandle(phThread[0]);
and
Code:
phThread[0] = NULL;
from the thread functions themselves, you will need the handles in the main thread to get the return code and for the WaitForMultipleObjects call.
Also the thread functions should be defined as returning a DWORD (you can just return 0).
See if that fixes your problem.
Last edited by Dave McLelland; August 11th, 2005 at 03:22 PM.
Dave Mclelland.
-
August 12th, 2005, 10:41 AM
#5
Re: Threads have sequential behavior
Well following ur advice the behavior is the same... with a diference the trhead ids are diferent but i realized it was cause i didnt put CloseHandle after waitformultipleobjects but with or without this ... when i do a test the service ever stops in the first thread till it finish its processing...
-
August 12th, 2005, 03:14 PM
#6
Re: Threads have sequential behavior
First, I dont want to appear patronising, but I dont know how much you know. So forgive some simple questions...
When you say you can realise that the "processing" is sequential, how do you know this?
How much work does each thread have to do (less than a second, seconds, minutes)?
Are you using a multiprocessor machine?
Two short lived threads may execute sequentially on a single processor machine, but actually execute simultaneously on a multiprocessor machine.
Dave Mclelland.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|