Bug 3885 – No multithread support for Windows DLL

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-03-06T08:16:00Z
Last change time
2015-06-09T05:14:40Z
Assigned to
sean
Creator
r.sagitario

Attachments

IDFilenameSummaryContent-TypeSize
583d_dll.zipdll test projectapplication/octet-stream2900
584dll_mt2.patchallow multithreading with dllstext/plain23101
585dll_mt1.patchallow multithreading with dlls in D1text/plain11442

Comments

Comment #0 by r.sagitario — 2010-03-06T08:16:32Z
Created attachment 583 dll test project There is currently no support for multithreading when creating DLLs. Here's a small test project that creates a DLL and builds three programs: test.exe: links against the import library of the DLL testdyn.exe: loads the DLL via LoadLibrary teststat.exe: links evreything without using DLLs (just for comparison). The test program creates 10 threads (in the case of testdyn.exe 5 before loading the library), and then calls a few functions mainly testing TLS access and memory corruption. This is for both D1 and D2, see the top of build.bat for DMD path and switching versions. Both test.exe and testdyn.exe produce access violations.
Comment #1 by r.sagitario — 2010-03-06T08:31:23Z
Created attachment 584 allow multithreading with dlls Here's a patch that fixes the issue for D2. It consists of 3 parts: 1. some modifications to core.thread to allow attaching and detaching to threads that are not the current thread. 2. a support file core.thread_helper to enumerate running threads, so that you can attach to these in DllMain 3. another support file core.dll_helper to fix the missing implicite TLS support on Windows XP. After applying the patch to druntime, the test project can be compiled with -version=use_patch to test it. Sorry, don't know enough for the Posix version, so there might be some issues to sort out.
Comment #2 by r.sagitario — 2010-03-06T08:35:50Z
Created attachment 585 allow multithreading with dlls in D1 this is a similar patch for D1: 1. some adjustments to std.thread to attach and detach threads. 2. the same thread_helper file, but with different module name and import.
Comment #3 by bugzilla — 2010-03-12T00:46:16Z
I've got these integrated in to Phobos and checked in now. Everyone who needs this, please give it a try!
Comment #4 by clugdbug — 2010-04-09T19:12:47Z
Fixed DMD1.058 and DMD2.042.