diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 3aef6f7b7..1d9d88534 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -102,7 +102,9 @@ namespace libtorrent int disk_allocations() const { return m_allocations; } #endif - + + void join(); + // aborts read operations void stop(boost::intrusive_ptr s); void add_job(disk_io_job const& j diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index e0fa982bc..886d5d891 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -62,12 +62,7 @@ namespace libtorrent disk_io_thread::~disk_io_thread() { - mutex_t::scoped_lock l(m_mutex); - m_abort = true; - m_signal.notify_all(); - l.unlock(); - - m_disk_io_thread.join(); + TORRENT_ASSERT(m_abort == true); } #ifndef NDEBUG @@ -95,6 +90,16 @@ namespace libtorrent #endif + void disk_io_thread::join() + { + mutex_t::scoped_lock l(m_mutex); + m_abort = true; + m_signal.notify_all(); + l.unlock(); + + m_disk_io_thread.join(); + } + // aborts read operations void disk_io_thread::stop(boost::intrusive_ptr s) { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index dd243e0f0..56ffbfe08 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2195,6 +2195,11 @@ namespace detail #endif m_checker_thread->join(); +#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) + (*m_logger) << time_now_string() << " waiting for disk io thread\n"; +#endif + m_disk_thread.join(); + TORRENT_ASSERT(m_torrents.empty()); TORRENT_ASSERT(m_connections.empty()); #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index c4ce276e2..c1c210cfa 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -130,6 +130,7 @@ void run_storage_tests(boost::intrusive_ptr info pm->async_read(r, bind(&on_read_piece, _1, _2, piece2, piece_size)); pm->async_release_files(none); + io.join(); } }