diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-07-29 20:22:54 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-07-29 20:22:54 +0200 |
| commit | e3c7656f9dc0acbaf518c051b847ee2e4eb7ba23 (patch) | |
| tree | 311f7ad01d1ef264778aebb2ad9b844c8015d068 /src/lib/encode_server.cc | |
| parent | 09860271bb6d03b3937c08bffb4c672697f6d711 (diff) | |
Fix bugs in thread termination causing occasional pthread
assertion failures.
Before this, it was possible for J2KEncoder::terminate_threads()
to finish without terminating all threads if the thread _running_
terminate_threads() was itself interrupt()ed.
This is because the thread_group::join_all() in terminate_threads()
is an interruption point, so it was possible it not to complete
but instead to throw interrupted_exception. Then the owning
J2KEncoder would be torn down but the threads would still be running,
causing use-after-frees.
This commit adds some boost::this_thread::disable_interruption
objects to ensure that the owning thread is not interrupted while
it is being destroyed.
Also tidy up code that does this stuff, assuming that it's safe
to not call thread::joinable but instead do
thread.interrupt();
try {
thread.join();
} catch (...) {}
Diffstat (limited to 'src/lib/encode_server.cc')
| -rw-r--r-- | src/lib/encode_server.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/lib/encode_server.cc b/src/lib/encode_server.cc index c30fc8f30..f4224798b 100644 --- a/src/lib/encode_server.cc +++ b/src/lib/encode_server.cc @@ -83,6 +83,8 @@ EncodeServer::EncodeServer (bool verbose, int num_threads) EncodeServer::~EncodeServer () { + boost::this_thread::disable_interruption dis; + { boost::mutex::scoped_lock lm (_mutex); _terminate = true; @@ -104,13 +106,9 @@ EncodeServer::~EncodeServer () } _broadcast.io_service.stop (); - if (_broadcast.thread.joinable()) { - try { - _broadcast.thread.join (); - } catch (...) { - - } - } + try { + _broadcast.thread.join (); + } catch (...) {} } /** @param after_read Filled in with gettimeofday() after reading the input from the network. |
