#3605: Dll's freeze with -threaded
------------------------------+---------------------------------------------
Reporter: NeilMitchell | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.12.1 RC1
Severity: normal | Resolution:
Keywords: | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
------------------------------+---------------------------------------------
Comment (by duncan):
My initial reaction is that calling `startupHaskell` from within `DllMain`
is a tad dodgy. The [http://msdn.microsoft.com/en-
us/library/ms682583(VS.85).aspx MSDN docs] say there are pretty severe
limitations on what can be done in it. In particular no calls to
LoadLibrary (or other functions that call LoadLibrary). This is because
the `DllMain` is called with a loader lock. So this is one possibility
that is consistent with the observed freeze.
It also says:
{{{
Calling functions that require DLLs other than Kernel32.dll
may result in problems that are difficult to diagnose. For
example, calling User, Shell, and COM functions can cause
access violation errors, because some functions load other
system components.
}}}
So to determine if `startupHaskell` is safe would require a full audit of
all the code it calls.
Another approach would be to trace the library load and see what OS /
library calls it is making.
There are more reasons to suggest that `startupHaskell` cannot safely be
run from within `DllMain`, the
[http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx MSDN Best
Practices for Creating DLLs] document states that:
{{{
You should never perform the following tasks from within DllMain:
}}}
including:
{{{
Call CreateThread. Creating a thread can work if you do not
synchronize with other threads, but it is risky.
}}}
Of course this is exactly what `startupHaskell` does, though only in the
case of multiple capabilities.
{{{
Use the memory management function from the dynamic C
Run-Time (CRT). If the CRT DLL is not initialized, calls
to these functions can cause the process to crash.
}}}
I expect the rts does this too.
Someone else should look this over but I suspect the thing to do is to
change the user guide (section 11.6) to stop recommending calling
`startupHaskell` inside `DllMain` and indeed to recommend never to do
that.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3605#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs