From 9899ffd244dd367ba69dffe1f21f4f0222064a46 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Sat, 11 Mar 2017 00:44:21 +0100 Subject: 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 Reviewed-by: Michael Stahl --- pyuno/source/module/pyuno_module.cxx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'pyuno/source/module') diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx index 40ed69e0191b..93a58111f6ae 100644 --- a/pyuno/source/module/pyuno_module.cxx +++ b/pyuno/source/module/pyuno_module.cxx @@ -318,7 +318,7 @@ static PyObject* getComponentContext( } static PyObject* initTestEnvironment( - SAL_UNUSED_PARAMETER PyObject*, SAL_UNUSED_PARAMETER PyObject*) + SAL_UNUSED_PARAMETER PyObject*, SAL_UNUSED_PARAMETER PyObject* args) { // this tries to bootstrap enough of the soffice from python to run // unit tests, which is only possible indirectly because pyuno is URE @@ -349,10 +349,21 @@ static PyObject* initTestEnvironment( mod.load(OStringToOUString(libname, osl_getThreadTextEncoding()), SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL); if (!mod.is()) { abort(); } - oslGenericFunction const pFunc( - mod.getFunctionSymbol("test_init")); - if (!pFunc) { abort(); } - reinterpret_cast(pFunc)(xMSF.get()); + assert(PyTuple_Check(args)); + if (PyTuple_Size(args) == 0) + { + oslGenericFunction const pFunc( + mod.getFunctionSymbol("test_init")); + if (!pFunc) { abort(); } + reinterpret_cast(pFunc)(xMSF.get()); + } + else + { + oslGenericFunction const pFunc( + mod.getFunctionSymbol("test_fini")); + if (!pFunc) { abort(); } + reinterpret_cast(pFunc)(); + } } catch (const css::uno::Exception &) { -- cgit