Load Dll multiple times to allow multi threading in .Net

前端 未结 3 615
悲哀的现实
悲哀的现实 2020-12-20 21:36

My .Net program uses a fortran Dll to perform a maths function (Arpack, solves eigen modes). I believe the fortran contains static varibles and generally isn\'t thread safe

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 22:11

    The workaround you found is actually a pretty decent one. There might be small odds that LoadLibraryEx() with the LOAD_LIBRARY_AS_IMAGE_RESOURCE option will work. That option allows you to load it multiple times. I seriously doubt it though, the DLL almost certainly relies on getting its runtime support code initialized through DllMain.

    One thing I didn't hear you mention is the pain of having to use GetProcAddress(). Make sure you do or you'll still stomp global variables when you start threading. Each thread must use its own address.

提交回复
热议问题