Hi Dan,
+/* Dummy thread just to initialize an MTA for the benefit of custom action DLLs */ +static HANDLE dummy_thread_event = NULL; +static HANDLE dummy_thread_handle = NULL;
+DWORD WINAPI dummy_thread_proc(void *arg)
It appears that calling CreateThread in DLL_PROCESS_ATTACH can cause deadlocks:
http://blogs.msdn.com/mgrier/archive/2005/06/21/431378.aspx
It might work if you move it to somewhere near ACTION_CallDllFunction, and wait for the thread to start up, but this remains a hack of course.
Another blog explains that inheritance of an existing MTA is just a side effect of starting the custom action in a different process, one that happens to have initialized an MTA already.
-Hans
On Sun, Jun 21, 2009 at 8:13 AM, Hans Leidekkerhans@codeweavers.com wrote:
It appears that calling CreateThread in DLL_PROCESS_ATTACH can cause deadlocks:
There seems to be a better explanation of the deadlock issues at http://blogs.msdn.com/oldnewthing/archive/2007/09/04/4731478.aspx I'm perfectly willing to believe that one should not create threads or wait for them to finish in DllMain, out of an abundance of caution, but I don't see how this particular case could deadlock.
I'm more worried about thread shutdown. It seems wrong to just hope that the thread finishes terminating before DllMain returns and the system calls FreeLibrary, but as oldnewthing explains, you can't wait for a thread to terminate inside DllMain.
It might work if you move it to somewhere near ACTION_CallDllFunction, and wait for the thread to start up, but this remains a hack of course.
What would the elegant solution be?
Another blog explains that inheritance of an existing MTA is just a side effect of starting the custom action in a different process, one that happens to have initialized an MTA already.
Sorry, I'm feeling dense. Which other blog, and what's interesting about that? - Dan
On Sunday 21 June 2009 07:39:39 pm Dan Kegel wrote:
I'm more worried about thread shutdown. It seems wrong to just hope that the thread finishes terminating before DllMain returns and the system calls FreeLibrary, but as oldnewthing explains, you can't wait for a thread to terminate inside DllMain.
I don't see a way to it cleanly in DllMain. You could ignore thread shutdown and let the system clean it up at process exit, but then you'd leak threads when an app keeps loading and unloading the dll.
However, it might work if you start the dummy thread right before running the first custom action and take it down after the last one has finished, e.g. in ACTION_FinishCustomActions.
What would the elegant solution be?
Running the custom action in a separate process.
Another blog explains that inheritance of an existing MTA is just a side effect of starting the custom action in a different process, one that happens to have initialized an MTA already.
Sorry, I'm feeling dense. Which other blog, and what's interesting about that?
Sorry, I should have looked it up:
http://blogs.msdn.com/astebner/archive/2005/02/07/368917.aspx
The interesting bit is in the comments.
-Hans