Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nagy
New Contributor I
58 Views

installing win32 structured exception handler

I'm working on a critical system that needs to be able to catch and handle win32 structured exceptions. In order to do this i need to install an exception handler into every thread using_set_se_translator (seehttp://msdn.microsoft.com/en-us/library/5z4bw5h5(VS.80).aspx).
What would be the best way to install such an handler into the internal tbb threads?
0 Kudos
6 Replies
Dmitry_Vyukov
Valued Contributor I
58 Views

Check out tbb::task_scheduler_observer::on_scheduler_entry() in task_scheduler_observer.h, it's what you need.

nagy
New Contributor I
58 Views

Thetask_scheduler_observer never seems to be called. What am I doing wrong?
[cpp]class Win32HandlerInstaller : public tbb::task_scheduler_observer
{
public:
	Win32HandlerInstaller()
	{
		observe(true);
	}

	void on_scheduler_entry( bool is_worker )
	{	
		Win32Exception::InstallHandler();
		CASPAR_LOG_INFO() << "Started TBB Worker Thread";
	} 

    void on_scheduler_exit( bool is_worker )
	{
		CASPAR_LOG_INFO() << "Ended TBB Worker Thread";
	}
};

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int)
{
	Win32HandlerInstaller();
	tbb::task_scheduler_init tbb_init;      
        Application app; 
        return app.Run(); // Doesnt return until applicaiton ends
}[/cpp]
EDIT: Added to main
Dmitry_Vyukov
Valued Contributor I
58 Views

I suspect you must create a bit more long-lived observer:
Win32HandlerInstaller observer;
nagy
New Contributor I
58 Views

Myapologies seems like i removed a bit to much of the main code. The main function doesn't return until the application ends.
Dmitry_Vyukov
Valued Contributor I
58 Views

But anyway Win32HandlerInstaller object is instantly destroyed (even before initialization of the scheduler).

nagy
New Contributor I
58 Views

Indeed, I stared blind on it.Embarrassing. Thank you for pointing that out.