NEED HELP: Thread Termination causes invalid page fault in Release built only 
Author Message
 NEED HELP: Thread Termination causes invalid page fault in Release built only

Hello specialists of Multithreading,

we have a not very clear problem here with the termination of worker threads
in MFC environement. We have a CWinApp Application with its thread and from
within there we create 3 Threads, which we create when the user hits a
"Start Button". The 3 threads are created like follows:
....
  AfxBeginThread(InspectionThread, pInspection,
THREAD_PRIORITY_TIME_CRITICAL);
....
from the Application Thread.

Now when we stop (like with a stop button) we send from the Running Worker
Thread a PostThreadMessage to the Application that the stop is pressed:

 AfxGetApp()->PostThreadMessage(WM_ACTIONSTOP, 0, (LPARAM)this);

Then each worker thread looks with into the application to check if he has
to stop .

If he has to stop we call SetThreadRunning(FALSE) which sets a flag that
this worker thread has stopped and calls AfxEndThread().

The Application Thread looks in the meantime if all thread are terminated.

 //wait for all threads to be terminated
 BOOL bThreadRunning = TRUE;
 while(bThreadRunning)
 {
  bThreadRunning = FALSE;
  POSITION posInsp = plistInspection->GetHeadPosition();
  while(posInsp != NULL)
  {
   CInspection* pInspection =
(CInspection*)plistInspection->GetNext(posInsp);
   if (pInspection->IsKindOf(RUNTIME_CLASS(CInspection)))
   { Sleep(10);
    bThreadRunning = bThreadRunning || pInspection->IsThreadRunning();
   }
  }
 }

All this works fine until we use the release build. We have the impression
the problem has to do with the treatment of the Messages (!) But we can't
localize it - what is wrong with this concept ?



Sun, 21 Apr 2002 03:00:00 GMT  
 NEED HELP: Thread Termination causes invalid page fault in Release built only
Well, for one thing I would not be polling the threads for completion;
instead, having set the boolean to FALSE, I'd do a
WaitForMultipleObjects(...) in the AND mode (wait for all objects)
waiting for the threads to terminate. I might even put a timeout in it
in case the threads are wedged. As to the release/debug issue, I'm not
sure. Note that PostThreadMessage makes sense only to a UI thread with
a message pump; a general worker thread would never see such a
message. Therefore the PostThreadMessage code doesn't seem to make
much sense. I'm more likely to suspect, in this case, that the debug
version does some debug cleanup of threads that the release version
does not do.
                        joe

On Wed, 3 Nov 1999 17:10:52 +0100, "WinMax"

Quote:

>Hello specialists of Multithreading,

>we have a not very clear problem here with the termination of worker threads
>in MFC environement. We have a CWinApp Application with its thread and from
>within there we create 3 Threads, which we create when the user hits a
>"Start Button". The 3 threads are created like follows:
>....
>  AfxBeginThread(InspectionThread, pInspection,
>THREAD_PRIORITY_TIME_CRITICAL);
>....
>from the Application Thread.

>Now when we stop (like with a stop button) we send from the Running Worker
>Thread a PostThreadMessage to the Application that the stop is pressed:

> AfxGetApp()->PostThreadMessage(WM_ACTIONSTOP, 0, (LPARAM)this);

>Then each worker thread looks with into the application to check if he has
>to stop .

>If he has to stop we call SetThreadRunning(FALSE) which sets a flag that
>this worker thread has stopped and calls AfxEndThread().

>The Application Thread looks in the meantime if all thread are terminated.

> //wait for all threads to be terminated
> BOOL bThreadRunning = TRUE;
> while(bThreadRunning)
> {
>  bThreadRunning = FALSE;
>  POSITION posInsp = plistInspection->GetHeadPosition();
>  while(posInsp != NULL)
>  {
>   CInspection* pInspection =
>(CInspection*)plistInspection->GetNext(posInsp);
>   if (pInspection->IsKindOf(RUNTIME_CLASS(CInspection)))
>   { Sleep(10);
>    bThreadRunning = bThreadRunning || pInspection->IsThreadRunning();
>   }
>  }
> }

>All this works fine until we use the release build. We have the impression
>the problem has to do with the treatment of the Messages (!) But we can't
>localize it - what is wrong with this concept ?

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
Author of "Win32 Programming" (with Brent Rector, Addison-Wesley, 1997)
Author of "Developing Windows NT Device Drivers" (with Ed Dekker, AWL, 1999)


Wed, 24 Apr 2002 03:00:00 GMT  
 NEED HELP: Thread Termination causes invalid page fault in Release built only
Thanks for your help - but unfortunatly this was an other problem - I
finally found it now :

The usage of ON_THREAD_MESSAGE needs a function with the two parameters
UINT, LPARAM due to a forced cast in the macro :(

Quote:

>Well, for one thing I would not be polling the threads for completion;
>instead, having set the boolean to FALSE, I'd do a
>WaitForMultipleObjects(...) in the AND mode (wait for all objects)
>waiting for the threads to terminate. I might even put a timeout in it
>in case the threads are wedged. As to the release/debug issue, I'm not
>sure. Note that PostThreadMessage makes sense only to a UI thread with
>a message pump; a general worker thread would never see such a
>message. Therefore the PostThreadMessage code doesn't seem to make
>much sense. I'm more likely to suspect, in this case, that the debug
>version does some debug cleanup of threads that the release version
>does not do.
> joe

>On Wed, 3 Nov 1999 17:10:52 +0100, "WinMax"

>>Hello specialists of Multithreading,

>>we have a not very clear problem here with the termination of worker
threads
>>in MFC environement. We have a CWinApp Application with its thread and
from
>>within there we create 3 Threads, which we create when the user hits a
>>"Start Button". The 3 threads are created like follows:
>>....
>>  AfxBeginThread(InspectionThread, pInspection,
>>THREAD_PRIORITY_TIME_CRITICAL);
>>....
>>from the Application Thread.

>>Now when we stop (like with a stop button) we send from the Running Worker
>>Thread a PostThreadMessage to the Application that the stop is pressed:

>> AfxGetApp()->PostThreadMessage(WM_ACTIONSTOP, 0, (LPARAM)this);

>>Then each worker thread looks with into the application to check if he has
>>to stop .

>>If he has to stop we call SetThreadRunning(FALSE) which sets a flag that
>>this worker thread has stopped and calls AfxEndThread().

>>The Application Thread looks in the meantime if all thread are terminated.

>> //wait for all threads to be terminated
>> BOOL bThreadRunning = TRUE;
>> while(bThreadRunning)
>> {
>>  bThreadRunning = FALSE;
>>  POSITION posInsp = plistInspection->GetHeadPosition();
>>  while(posInsp != NULL)
>>  {
>>   CInspection* pInspection =
>>(CInspection*)plistInspection->GetNext(posInsp);
>>   if (pInspection->IsKindOf(RUNTIME_CLASS(CInspection)))
>>   { Sleep(10);
>>    bThreadRunning = bThreadRunning || pInspection->IsThreadRunning();
>>   }
>>  }
>> }

>>All this works fine until we use the release build. We have the impression
>>the problem has to do with the treatment of the Messages (!) But we can't
>>localize it - what is wrong with this concept ?

>Joseph M. Newcomer [MVP]

>Web: http://www3.pgh.net/~newcomer
>MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
>Author of "Win32 Programming" (with Brent Rector, Addison-Wesley, 1997)
>Author of "Developing Windows NT Device Drivers" (with Ed Dekker, AWL,

1999)


Sat, 04 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. MSDEV causing invalid page fault: HELP!

2. MSDEV causing invalid page fault: HELP!

3. caused an invalid page fault in module ...

4. MSDEV caused an invalid page fault in Module SSSCC.DLL After Install SP2

5. CONNECT caused an invalid page fault in module KERNEL32.DLL at 017f:bff7b9f2

6. MSDEV.EXE caused an invalid page fault in module SSSCC.DLL

7. RasHangUp() -> RNAAPP causing invalid page fault

8. 3rd party implicit (load-time) dll when exitting app causes invalid page fault

9. GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll

10. What causes invalid page fault?

11. Invalid Page Fault in Release mode with ML compiler option

12. Invalid Page Fault in Release mode with ML compiler option

 

 
Powered by phpBB® Forum Software