j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
175 stars 14 forks source link

Thread-Local Storage #297

Open foxtran opened 1 year ago

foxtran commented 1 year ago

Dear all,

I implemented a multi-threaded library in Fortran and C++, and on the Fortran side, I need thread-local variables for making Fortran-side thread-safe. Currently, thread-local variables are possible to implement via OpenMP, unfortunately, it does not give any guarantees when the threads library is used for parallelization. I found that the IBM compiler supports only thread-local common blocks via directives to the compiler (see more here: https://www.ibm.com/docs/en/xl-fortran-aix/16.1.0?topic=directives-threadlocal).

So, I would like to have in modern Fortran threadlocal keyword for any available data. Probably, it can be written as:

  integer, threadlocal :: variable

I also found some useful documents which describe the use cases of TLS:

tkoenig1 commented 1 year ago

That would require a whole thread model for Fortran, I think.

PierUgit commented 1 year ago

If a threading library is used, then providing threadlocal allocations should be responsability of the library.