Wielowątkowość i wyjątki

0

Otóż mam takie 3 pliczki:

main.cpp

#include <cstdlib>
#include <iostream>
#include "testexception.h"

using namespace std;

int main(int argc, char *argv[])
{
	for (int i=0; i<5; i++){ 
		new testException(i);
	}
    system("PAUSE");
    return EXIT_SUCCESS;
}
////////////testException.cpp///////////////////////////////////////////////////////////////////////////////////////////////
#include "testException.h"
#include <stdio.h>

testException::testException(int index){
	this->index= index;
	createThread();
}

testException::~testException(){
}

bool testException::createThread (){
		par*	this_param = new par;
		this_param->te	= this;
			this->hThread = ::CreateThread(NULL, 0, 
				(unsigned long (__stdcall *)(void *))this->runProcess, 
				(void *)(this_param), 0, &this->hThreadId);
	
		return this->hThread ? true : false;
}

DWORD testException::runProcess (void* Param){
	testException* te= ( ( par*)Param)->te;
	int count=0;
	do{
		try{
			count++;
			printf("Throw %d - %d\n",te->index, count);
			throw 11;
		}catch (int& a){
			printf("Catch %d - %d\n",te->index, a);
		}
		Sleep(50);
	}while (count<400);
	printf("Koniec :%d \n",te->index);
	return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////testException.h/////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef TESTEXCEPTION_H_
#define TESTEXCEPTION_H_

#include <windows.h>

class testException
{
public:
	testException(int index);
	virtual ~testException();
	
	bool 	createThread ();
	static DWORD 	runProcess (void* Param);
	
private:
	DWORD		hThreadId;
	HANDLE		hThread;
	int index;
};

struct par {
	testException*	te;
};

#endif /*TESTEXCEPTION_H_*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Czy ktoś może mi powiedzieć, dlaczego to nie działa? Program przerywa swoje działanie po kilku printfach. ;(

0

MinGW-GCC [???]

-mthreads
Support thread-safe exception handling on Mingw32. Code that relies on thread-safe exception handling must compile and link all code with the -mthreads option. When compiling, -mthreads defines -D_MT; when linking, it links in a special thread helper library -lmingwthrd which cleans up per thread exception handling data.

1 użytkowników online, w tym zalogowanych: 0, gości: 1