Exception problems-> this is a bug!

Joost Kraaijeveld J.Kraaijeveld@Askesis.nl
Tue Nov 28 07:26:00 GMT 2000


This program (see below) crashes whenever a function on a separate thread is
called that contains a try{} catch(){} block. I tested with several
compilers (Cygwin, MingW, IBM Visual Age, MS Visual C++ and Metrowerks) and
only CygWin (latest release of all software) crashes. I think that the stack
of the thread is not cleaned up correctly.
Is there a workaround availalbe of some kind??
 
Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
email: J.Kraaijeveld@Askesis.nl
web: www.askesis.nl 
 
////////////// source ///////////////////
#include <cstdio>
#include <cstdlib>
#include <windows.h>
extern "C" unsigned long WINAPI runFunction1(void* aAThreadFunction)
{
 for ( unsigned long i = 0;i<5;i++)
 {
 printf("%lu\n",i);
 Sleep(200);
 }
 return 0;
}
extern "C" unsigned long WINAPI runFunction2(void* aAThreadFunction)
{
 try
 {
 for ( unsigned long i = 0;i<5;i++)
 {
 printf("%lu\n",i);
 Sleep(200);
 }
 }
 catch(...)
 {
 }
 return 0;
}
class ATest
{
 public:
 void print()
 {
 runFunction2(0);
 }
};
extern "C" unsigned long WINAPI runFunction3(void* aAThreadFunction)
{
 ATest t;
 t.print();
 return 0;
}
int main(int argc, char* argv[])
{
 LPTHREAD_START_ROUTINE threadFunction;
 // No arguments, run runFunction1
 if(argc == 1)
 {
 threadFunction = runFunction1;
 }else if(argc == 2)
 {
 unsigned long functionNumber = atoi(argv[1]);
 switch(functionNumber)
 {
 case 1:
 {
 threadFunction = runFunction1;
 break;
 }
 case 2:
 {
 threadFunction = runFunction2;
 break;
 }
 case 3:
 {
 threadFunction = runFunction3;
 break;
 }
 }
 }else
 {
 printf("Run this program with 0 or 1 argument(s), see source\n ");
 return 1;
 }
 HANDLE threadHandles[2];
 unsigned long threadIds[2];
 // Create two threads
 threadHandles[0] = CreateThread(
NULL,0,threadFunction,NULL,0,&threadIds[0]);
 threadHandles[1] = CreateThread(
NULL,0,threadFunction,NULL,0,&threadIds[1]);
 // Wait for the threads to end
 WaitForMultipleObjects(2,&threadHandles[0],true,INFINITE);
 return 0;
}
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /