Search code examples
dllddmd

What problems can be expected using D1 and dlls?


What problems can I expect using a dll compiled using dmd compiler (D1) if c++ program calls that dll and that c++ program is multithreaded?


Solution

  • D uses a stop-the-world garbage collector, which means that it needs to be able to pause all threads that access D-managed memory during a collection. In order to do that, the runtime must have a list of these threads.

    The D2 guideline for Writing Win32 DLLs in D has instructions on adding DLL_THREAD_ATTACH/DLL_THREAD_DETACH handlers to notify the runtime of new threads, however the D1 version of the article only mentions that "Multiple threads not supported yet". Thus, if you're forced to use D1, you will probably have to synchronize all of your DLL's entry points (exported functions) using a global lock, or somehow else take care of the synchronization.