fixed some openmp + TLS/related crashes

metadata
Wenzel Jakob 2013-02-06 19:40:15 -05:00
parent 403706fa62
commit 30efd3c151
3 changed files with 32 additions and 4 deletions

View File

@ -242,6 +242,10 @@ public:
}
}
#if defined(MTS_OPENMP)
Thread::initializeOpenMP(nCores);
#endif
int it = 0;
while (m_running)
photonMapPass(++it, queue, job, film, sceneResID, sensorResID, indepSamplerResID);

View File

@ -187,6 +187,10 @@ public:
enableFPExceptions();
#endif
#if defined(MTS_OPENMP)
Thread::initializeOpenMP(nCores);
#endif
int it=0;
while (m_running) {
distributedRTPass(scene, samplers);

View File

@ -396,6 +396,7 @@ static boost::mutex __unmanagedMutex;
#if defined(MTS_OPENMP) && defined(__OSX__)
static int __omp_threadCount = 0;
static pthread_key_t __omp_key;
static bool __omp_key_created;
int mts_omp_get_max_threads() {
/* This function exists to sidestep an annoying
@ -451,6 +452,8 @@ void Thread::staticShutdown() {
ThreadPrivate::self = NULL;
detail::destroyGlobalTLS();
#if defined(__OSX__)
if (__omp_key_created)
pthread_key_delete(__omp_key);
__mts_autorelease_shutdown();
#endif
}
@ -461,19 +464,25 @@ void Thread::initializeOpenMP(size_t threadCount) {
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
#if defined(__OSX__)
if (!__omp_key_created) {
pthread_key_create(&__omp_key, NULL);
__omp_key_created = true;
}
__omp_threadCount = threadCount;
pthread_key_create(&__omp_key, NULL);
#endif
if (omp_get_dynamic())
omp_set_dynamic(0);
omp_set_num_threads((int) threadCount);
omp_set_dynamic(false);
int counter = 0;
#pragma omp parallel
{
#if defined(__OSX__)
pthread_setspecific(__omp_key, reinterpret_cast<void *>(counter));
if (!pthread_getspecific(__omp_key))
pthread_setspecific(__omp_key, reinterpret_cast<void *>(counter));
#endif
detail::initializeLocalTLS();
Thread *thread = Thread::getThread();
@ -484,14 +493,25 @@ void Thread::initializeOpenMP(size_t threadCount) {
formatString("omp%i", counter));
counter++;
}
const std::string threadName = "Mitsuba: " + thread->getName();
#if defined(__LINUX__)
prctl(PR_SET_NAME, threadName.c_str());
#elif defined(__OSX__)
pthread_setname_np(threadName.c_str());
#elif defined(__WINDOWS__)
SetThreadName(threadName.c_str());
#endif
thread->d->running = false;
thread->d->joined = false;
thread->d->fresolver = fResolver;
thread->d->logger = logger;
thread->incRef();
ThreadPrivate::self->set(thread);
#pragma omp critical
__unmanagedThreads.push_back((UnmanagedThread *) thread);
__unmanagedThreads.push_back((UnmanagedThread *) thread);
}
}
#else