Thread-safetyness of exceptions Topic is solved
Thread-safetyness of exceptions
Is it safe to use exceptions within threads?
"It is like doing a foo to bar over a double baz, backwards." -Ymer
Code: Select all
void CThread::Entry(void)
{
try
{
printf("%i running in %p\n", wxThread::GetCurrentId(), this);
wxThread::Sleep(3000);
printf("%p %i throwing %s\n", this, wxThread::GetCurrentId(), "foo");
throw "foo";
}
catch(const char* psz)
{
printf("%p %i catching %s\n", this, wxThread::GetCurrentId(), psz);
}
}
Code: Select all
3256 running in 025249B8
3816 running in 02524AB0
025249B8 3256 throwing foo
02524AB0 3256 catching foo
But then the threads execute in different functions everything works like it should.
"It is like doing a foo to bar over a double baz, backwards." -Ymer
-
- Knows some wx things
- Posts: 45
- Joined: Wed Jun 15, 2005 5:47 pm
-
- I live to help wx-kind
- Posts: 196
- Joined: Tue Dec 07, 2004 8:54 pm
- Location: Essen, Germany
I entered your thread code to a function of the console sample. It looks like
The output is
BTW, the original wxThread::Entry methods returns wxThread::ExitCode (decared as void *).
Code: Select all
wxThread::ExitCode MyDetachedThread::Entry()
{
try
{
printf("%i running in %p\n", wxThread::GetCurrentId(), this);
wxThread::Sleep(3000);
printf("%p %i throwing %s\n", this, wxThread::GetCurrentId(), "foo");
throw "foo";
}
catch(const char* psz)
{
printf("%p %i catching %s\n", this, wxThread::GetCurrentId(), psz);
} {
wxCriticalSectionLocker lock(gs_critsect);
if ( gs_counter == (size_t)-1 )
gs_counter = 1;
else
gs_counter++;
}
for ( size_t n = 0; n < m_n; n++ )
{
if ( TestDestroy() )
{
m_cancelled = true;
break;
}
wxPutchar(m_ch);
fflush(stdout);
wxThread::Sleep(100);
}
return 0;
}
Can you do the same modification on your pc? Do you have similar output? If yes, then please post the threads declaration and creation code.*** Testing detached threads ***
336 running in 009569D8
2548 running in 00958140
880 running in 00956980
009569D8 336 throwing foo
00958140 2548 throwing foo
00956980 880 throwing foo
009569D8 336 catching foo
00958140 2548 catching foo
00956980 880 catching foo
BCABCABCABCABCABCABCABCABCABCA
BTW, the original wxThread::Entry methods returns wxThread::ExitCode (decared as void *).