- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I have a DLL with module variables, is it safe to call functions that use those variables in a parallel process? I want to avoid passing the debug level and output file to all of my functions in a DLL. So instead, my first function call into the DLL initializes 2 private module variables in the module logging: output_file and debug_level. Then I define a subroutine write_to_log( message ). In a non-parallel application, from anywhere in the dll I can say "use logging" and simply write "call write_to_log( some_message )." If I have multiple threads using this library, will all my logging messages go to the output file initialized by the last logging initialization call? My understanding is that they will not, but they would if I declared the variables in a common block. Is this correct?
If this question has been asked before and I missed it, or if there are any references out there please point me in that direction. Thanks for your time!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Aaron
Did you use static local variable in your write_to_log function? I have to say both the static local veriable and common block are unsafe in mult-threading application. Because they all can be accessed by different threads at the same time. To use those shared variables, you must synchronize them before access. There are many ways to synchronize objects depending on how you multi-threads your code.
Here is an article on threading fortran applications. You can have a look at the section: Thread Safety for detail:
Here is also a similar discussion for your referenece:
https://software.intel.com/en-us/forums/topic/369135
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Module variables are also static, like COMMON, and need to be protected if used in a multithreaded environment.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page