Issue 107562 - rtl_cache_wsupdate_fini deadlocks process upon unloading sal3.dll
Summary: rtl_cache_wsupdate_fini deadlocks process upon unloading sal3.dll
Status: CONFIRMED
Alias: None
Product: porting
Classification: Code
Component: code (show other issues)
Version: DEV300m66
Hardware: PC Windows, all
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-09 14:35 UTC by Stephan Bergmann
Modified: 2013-10-28 09:50 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
reproduce the problem (715 bytes, text/plain)
2009-12-09 14:37 UTC, Stephan Bergmann
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description Stephan Bergmann 2009-12-09 14:35:40 UTC
On Windows, in certain scenarios of unloading sal3.dll it happens that the
process deadlocks.  The main thread calls sal3.dll's DllMain
(DLL_PROCESS_DETACH), which calls rtl_cache_wsupdate_fini, which blocks in
WaitForSingleObject on the m_update_thread.  The m_update_thread has already
returned from its rtl_cache_wsupdate_all function, but is blocked in some
sysenter instruction.  The MS "Best Practices for Creating DLLs" document
(available from <http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx>)
states:  "You should never perform the following tasks from within DllMain:
[...] Synchronize with other threads.  This can cause a deadlock."

A simple scenario in which the deadlock can be observed is the attached
deadlock.patch, which in the sal code module creates and runs a small C
application that dynamically loads and frees sal3.dll.  (I stumbled over this
problem in a similar scenario, where the DllPlugInTester_dll.exe that is part of
CppUnit 1.12.1 dynamically loads and frees a test library that links against
sal3.dll.)  The problem seems not to appear with typical OOo executables that
use sal3.dll, maybe because those executables are themselves linked against
sal3.dll.
Comment 1 Stephan Bergmann 2009-12-09 14:37:04 UTC
Created attachment 66569 [details]
reproduce the problem
Comment 2 Steve Yin 2013-10-28 09:50:40 UTC
Can we simply remove WaitForSingleObject? 
Debugging with soffice.bin and found when calling rtl_cache_wsupdate_fini, only main thread exists. I think soffice.bin may kill all the other threads includes m_update_thread before it. And there is nothing to do with the process such as clean the static structs or something like that at this time, because the process will be terminated, all its memory will be released by Windows.