If we can't join all the threads before destroying a mutex (#31735 (moved)), and we can't otherwise prevent multiple thread access, we should stop destroying that mutex. (Because destroying a locked thread invokes undefined behaviour.)
There may be some other pattern that helps us destroy all but one mutex. But that involves a "mutex-destruction" mutex. Which is terribly complex.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items 0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Linked items 0
Link issues together to show that they're related.
Learn more.
Hi! This all looks plausible to me at first glance. Here's another question to check on, however:
Have you thought about what happens on re-initialization?
(Ideally, if Tor finishes, and then is re-initialized in the same process, we would reuse the existing mutexes rather than creating new ones. Is that achievable?)
Trac: Owner: N/Ato teor Status: needs_review to assigned
There's some code that could be used for an integration test, but it would need work. See the configure option --enable-restart-debugging and the corresponding environment variable TOR_DEBUG_RESTART, both added in 97d9ba2380e0c894a1b611bdb4f35d0fe98a837a.
Hi! This all looks plausible to me at first glance. Here's another question to check on, however:
Have you thought about what happens on re-initialization?
We must destroy the mutexes, or re-initialising them triggers undefined behaviour. (On both pthreads and Windows threads.) And there is no way to determine if the mutex has already been initialised.
Therefore, we should continue to use the old code, but:
avoid freeing some locked mutexes by acquiring and releasing the lock in tor_mutex_uninit(), and
add comments explaining the issue, so we can diagnose any crashes or deadlocks more easily.
I found another fix that might be much safer: using a sentinel variable to only initialise global mutexes once, regardless of the number of times that tor is re-initialised. (We already do this with the logs, so that we can keep seeing logs during shutdown.)
I updated the usage comments in this branch, and added a note to #31735 (moved).
Trac: Status: merge_ready to needs_review Actualpoints: 0.4 to 0.5