- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
This might be a naive question.
I have a DLL that exports only functions. These functions share a COMMOM block in the dll source files.
When a common block is declared in a dll, is this block available to all instances of the DLL loaded by one application ?
I have an windows application that creates multiple threads. Some of these threads load the fortran dll and make some function calls. The problem is on thread modifies the variables in the common block - then is this change visible in all other dll instances ?
thank you.
vikrantca
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is this all in one process? If it was, I'd expect that the DLL would be loaded just once and the address space shared. But it's possible that multiple LoadLibrary requests might load it multiple times. It would be useful to add some debugging code to see what handles are returned by LoadLibrary in the various threads and if calls to GetProcAddr in the various threads return the same value for the same routine.
It is possible to create a DLL with a data section that is read-write shared across multiple processes - requires an option when linking.
It is possible to create a DLL with a data section that is read-write shared across multiple processes - requires an option when linking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So does this mean that when multiple threads from the same process call LoadLibrary they would see the same COMMON section ?
BTW, I tried that and yes, the same handle is returned by LoadLibrary when all the threads are from the same process.
The code that I have uses some shared data in COMMON block amongst functions, but I want this data to separate for each calling thread. I guess modules would be the right choice.
thanks
vikrantca
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, you WANT the data to be separate! Modules would not help - they would be global for the process too. You may want to consider using OpenMP which provides standardized ways of specifying whether variables are to be shared or not. It's not clear to me why you're loading the DLL in multiple threads, though. That's a process-wide operation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a wrapper class in c# that loads the fortran dll for some fluid (air, water) calculations. The dll is initialized with a property model (air or water or carbon etc.). This model is stored in the common section.
The different threads of the process use different fluids, thus the common section is overwritten by the most recent initialization call. The initialization is an expensive call. So each instance of the c# class calls initialize only once at the beginning. So the most recent call takes precendence.
Any suggestions you may have would be very helpful.
thank you.
vikrantca
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would have to recommend that you don't use global variables of any kind. Declare local variables in the main DLL routine and either have any subroutines be "contained", so that the variables are visible, or pass them around as arguments. Be sure that you add the RECURSIVE keyword to all your routines and link against the multithread version of the Fortran libraries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot.
vikrantca
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page