Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

installing win32 structured exception handler

nagy
New Contributor I
660 Views
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
660 Views
Check out tbb::task_scheduler_observer::on_scheduler_entry() in task_scheduler_observer.h, it's what you need.

0 Kudos
nagy
New Contributor I
660 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
0 Kudos
Dmitry_Vyukov
Valued Contributor I
660 Views
I suspect you must create a bit more long-lived observer:
Win32HandlerInstaller observer;
0 Kudos
nagy
New Contributor I
660 Views
Myapologies seems like i removed a bit to much of the main code. The main function doesn't return until the application ends.
0 Kudos
Dmitry_Vyukov
Valued Contributor I
660 Views
But anyway Win32HandlerInstaller object is instantly destroyed (even before initialization of the scheduler).

0 Kudos
nagy
New Contributor I
660 Views
Indeed, I stared blind on it.Embarrassing. Thank you for pointing that out.
0 Kudos
Reply