diff --git a/ChangeLog b/ChangeLog index 6a7c8deaf3..e6eca0de1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,9 @@ Changes in version 0.2.1.1-alpha - 2008-??-?? most smartlists hold around 8-12 elements tops. - Avoid allocating extra space when computing consensuses on 64-bit platforms. Bug spotted by aakova. + - Use recursive pthread mutexes in order to avoid deadlock when + logging debug-level messages to a controller. Bug spotted by + nwf, bugfix on 0.2.0.16-alpha. o Minor features: - Allow separate log levels to be configured for different logging diff --git a/src/common/compat.c b/src/common/compat.c index 34b4ffae18..b92fa48ded 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -1735,13 +1735,14 @@ tor_get_thread_id(void) struct tor_mutex_t { pthread_mutex_t mutex; }; +static pthread_mutexattr_t attr_reentrant; /** Allocate and return new lock. */ tor_mutex_t * tor_mutex_new(void) { int err; tor_mutex_t *mutex = tor_malloc_zero(sizeof(tor_mutex_t)); - err = pthread_mutex_init(&mutex->mutex, NULL); + err = pthread_mutex_init(&mutex->mutex, &attr_reentrant); if (PREDICT_UNLIKELY(err)) { log_err(LD_GENERAL, "Error %d creating a mutex.", err); tor_fragile_assert(); @@ -1857,6 +1858,10 @@ tor_cond_signal_all(tor_cond_t *cond) void tor_threads_init(void) { +#ifdef USE_PTHREADS + pthread_mutexattr_init(&attr_reentrant); + pthread_mutexattr_settype(&attr_reentrant, PTHREAD_MUTEX_RECURSIVE); +#endif } #elif defined(USE_WIN32_THREADS) #if 0