cmacmackin / flogging

Fortran logging library
GNU Lesser General Public License v3.0
56 stars 3 forks source link

Make output threadsafe #2

Open cmacmackin opened 7 years ago

cmacmackin commented 7 years ago

@jacobwilliams @zbeekman

I want this library to be thread-safe. It's been designed so that there are no global variables, but I'm thinking that the output operations could cause problems. How was this addressed in json-fortran?

zbeekman commented 7 years ago

I believe (but @jacobwilliams did all of the work on this) that we assume that the user manages their threads for IO not be an issue, but I may be mistaken. If you want to relive them of this burden then you need a serialization mechanism, which then in-turn implies you know what parallel programming implementation they are using (pthreads vs openmp etc.) which then means you need to commit to using one or more of these implementations to achieve serialization. Also things get tricky with compiler buffering. For now I would shirk that responsibility off on the user/client-code... my $0.02

jvo203 commented 2 years ago

I use pthreads inside C and then OpenMP from within FORTRAN at the same time. Would protecting all logger%info() calls with a mutex (e.g. glib GMutex) inside FORTRAN be enough to ensure flogging thread safety?