summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-03-11 00:44:21 +0100
committerMichael Stahl <mstahl@redhat.com>2017-03-11 10:08:06 +0000
commit9899ffd244dd367ba69dffe1f21f4f0222064a46 (patch)
tree5b0a076e2216e9e189b811ce2fcffc23af5910e5 /comphelper
parentaa204f1c09a760d6753c408376ab7307fb13ad91 (diff)
comphelper: fix MSVC hang in ThreadPool::shutdown()
Commit aa68c99d88fd7abe08c4aee5206c859a0cdba38e added some code using std::condition_variable to comphelper. Built with MSVC 2017, this causes many cppunittester.exe processes to deadlock in ThreadPool::shutdown(): maTasksChanged.notify_all(); This ultimately calls NtReleaseKeyedEvent(), which never returns. The reason appears to be a bug in Windows 7, for which a "hotfix"[1] is avaiable here, but it's apparently not distributed via Windows Update so we likely can't rely on users or even developers having this installed. However, the documentation of DllMain[2] and ExitProcess[3] indicates that during shutdown, by the time global destructors are invoked all threads other than the one that called ExitProcess have already been terminated. Returning from main() implicitly calls ExitProcess [4]. As it turns out the problem only happens for some CppUnitTests because soffice.bin will call ThreadPool::shutdown() from Desktop::doShutdown() while it is still safe. [1] http://support.microsoft.com/kb/2582203 [2] https://msdn.microsoft.com/en-US/library/windows/desktop/ms682583(v=vs.85).aspx [3] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx [4] https://blogs.msdn.microsoft.com/oldnewthing/20100827-00/?p=13023 Change-Id: I6137461ca7efe9a5fbe4f8f8478fb96de3570469 Reviewed-on: https://gerrit.libreoffice.org/35066 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/threadpool.cxx8
1 files changed, 7 insertions, 1 deletions
diff --git a/comphelper/source/misc/threadpool.cxx b/comphelper/source/misc/threadpool.cxx
index 712009d8a2b4..1219ef24b986 100644
--- a/comphelper/source/misc/threadpool.cxx
+++ b/comphelper/source/misc/threadpool.cxx
@@ -89,7 +89,12 @@ ThreadPool::ThreadPool( sal_Int32 nWorkers ) :
ThreadPool::~ThreadPool()
{
- shutdown();
+ // note: calling shutdown from global variable dtor blocks forever on Win7
+ // note2: there isn't enough MSVCRT left on exit to call assert() properly
+ // so these asserts just print something to stderr but exit status is
+ // still 0, but hopefully they will be more helpful on non-WNT platforms
+ assert(mbTerminate);
+ assert(maTasks.empty());
}
struct ThreadPoolStatic : public rtl::StaticWithInit< std::shared_ptr< ThreadPool >,
@@ -127,6 +132,7 @@ sal_Int32 ThreadPool::getPreferredConcurrency()
return ThreadCount;
}
+// FIXME: what does "this" refer to in the following?
// FIXME: there should be no need for this as/when our baseline
// is >VS2015 and drop WinXP; the sorry details are here:
// https://connect.microsoft.com/VisualStudio/feedback/details/1282596