From c52c0763649809f7fee714b94e7a5343e6cca840 Mon Sep 17 00:00:00 2001 From: Edgar Velazquez-Armendariz Date: Mon, 28 Jan 2013 01:53:40 -0500 Subject: [PATCH 1/2] Also allow TLS to access the dying thread during Thread::staticShutdown --- src/libcore/thread.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcore/thread.cpp b/src/libcore/thread.cpp index efd38dd1..c6eabcd7 100644 --- a/src/libcore/thread.cpp +++ b/src/libcore/thread.cpp @@ -446,10 +446,9 @@ void Thread::staticShutdown() { __unmanagedThreads[i]->decRef(); __unmanagedThreads.clear(); getThread()->d->running = false; - ThreadPrivate::self->set(NULL); + detail::destroyLocalTLS(); delete ThreadPrivate::self; ThreadPrivate::self = NULL; - detail::destroyLocalTLS(); detail::destroyGlobalTLS(); #if defined(__OSX__) __mts_autorelease_shutdown(); From 8ca3bbaaab0d9bc4fff9413ebdc2d0016c96eddf Mon Sep 17 00:00:00 2001 From: Edgar Velazquez-Armendariz Date: Mon, 28 Jan 2013 01:57:45 -0500 Subject: [PATCH 2/2] Do not try to log to a null logger (can happen during Thread::staticShutdown) --- include/mitsuba/core/logger.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mitsuba/core/logger.h b/include/mitsuba/core/logger.h index 8e7c1f15..f3fd5846 100644 --- a/include/mitsuba/core/logger.h +++ b/include/mitsuba/core/logger.h @@ -37,7 +37,7 @@ MTS_NAMESPACE_BEGIN if (EXPECT_NOT_TAKEN(thread == NULL)) \ throw std::runtime_error("Null thread pointer"); \ mitsuba::Logger *logger = thread->getLogger(); \ - if (level >= logger->getLogLevel()) \ + if (logger != NULL && level >= logger->getLogLevel()) \ logger->log(level, m_theClass, \ __FILE__, __LINE__, fmt, ## __VA_ARGS__); \ } while (0) @@ -51,7 +51,7 @@ MTS_NAMESPACE_BEGIN if (EXPECT_NOT_TAKEN(thread == NULL)) \ throw std::runtime_error("Null thread pointer"); \ mitsuba::Logger *logger = thread->getLogger(); \ - if (level >= logger->getLogLevel()) \ + if (logger != NULL && level >= logger->getLogLevel()) \ logger->log(level, NULL, \ __FILE__, __LINE__, fmt, ## __VA_ARGS__); \ } while (0)