Re: multithreading in drivers? by Meier
Meier
Tue Mar 22 07:15:22 CST 2005
> This is all you so here?
not really... at the end... but for testing it's enough
>> DWORD WINAPI CServiceData::DoUpdate(LPVOID lpParameter)
>> {
>> return 0;
>> }
>
> Why do you want it to be created suspended?
> Are you sure you need that?
no, I don't need this... but if I don't create it suspended it doesn't help
much... I thought, maybe it helps
to set another thread priority, befor starting it the first time... that's
why it's in there
>> void doIt()
>> {
>> DWORD dwThreadID;
>> HANDLE hThread = ::CreateThread(NULL, 0, CServiceData::DoUpdate, NULL,
>> CREATE_SUSPENDED, &dwThreadID);
>
> You don't need to do this, it's already set to normal.
>> ::SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL); // nur zur
>> Sicherheit
>>
>> if (hThread != NULL)
>> {
>> ::ResumeThread(hThread);
yes, normally I use this... but like this, you can put in break-points, when
it's executed and hangs in this loop... if it hangs in the
"WaitForSingleObject", it's not that easy to get it out there...
> If you want to wait for a thread to terminate you shoud use
> WaitForSingleObject on the thread handle with a infinite timeout and non
> in
> intterupitble mode.
>
>> DWORD dwExitCode;
>> ::GetExitCodeThread(hThread, &dwExitCode);
>> while(dwExitCode == STILL_ACTIVE)
>> {
>> ::Sleep(50);
>> ::GetExitCodeThread(hThread, &dwExitCode);
>> }
>>
>> CloseHandle(hThread);
>> }
... and where's a bug now? :-(
MR