Create thread_safety.md
Thank you for contributing to cddlib :)
Please make sure that your Pull Request contains an entry in news/ so others know how cddlib has improved.
To create a news entry, copy the news/TEMPLATE.rst to news/yourbranch.rst, fill out the relevant sections, and delete the inappropriate ones. These news entries will be combined into the changelog with the next release.
Should we test that _Thread_local is available in our configure.ac or explicitly select the C11 standard? I don't think that's the default for compilers.
I guess, the question is also whether we want to require C11 which might be an issue for some distributions.
We can call e.g. AX_TLS and error out if it fails, or (a bit harder) redefine _Threads_local to nothing. We can even mess around with checking whether -std=c11 flag is needed.
How far do we want to go with it? I think in 2022 supporting nonconforming to C11 compilers is kind of retro-computing I don't care much about. One way to check whether this is needed at all is just to release like this, and wait for complaints...
So, _Thread_local works since GCC 4.9 without explicitly setting -std=c11. Same since clang 3.3, icc 17, Without setting flags it's not recognized by any version of msvc.
So, these versions of GCC, clang, icc are sufficiently ancient that it's not worth our while. We don't really provide build scripts for MSVC so I think we can safely ignore this.
Hi, as the author of TOPCOM I was going to ask whether there could be an official new version of cddlib that contains the thread-safety patch as it was merged into the current cddlib-master. That way it would be unnecessary to distribute a patched version of cddlib with TOPCOM. To me it seems that "m" is still the latest version, and this is not yet thread-safe, right?
Thanks for considering!
Jörg
I was thinking we'd need a test program for thread-safery. Could you perhaps cut something out of TopCom code for this purpose?
I think cutting something out of TOPCOM and make it compilable "standalone" would be pretty difficult (any reasonable functionality depends too deeply on the TOPCOM library, which a test code for cddlib probably does not want to rely on).
For a check independent of TOPCOM, it would probably be best to let multiple threads concurrently loop over the existing test codes like testlp1.c etc. using a fixed existing input file. That is, one would have to
- generate valid C++-files from the test codes in cddlib-master/src/
- fix the input files in the resulting codes to an existing input file
- in each C++-file shift the body of main into a function, e.g., "run_testlp1", in which the body is repeated for a sufficient number of repetitions to create some substantial run-time
- call that function in standard thread generating and joining loops inside a new C++-main
Most probably, the functions triggering inputs and outputs are not thread-safe even with your modifications. But all input/output has to be guarded by a mutex outside cddlib anyway to avoid interleaved screen output. It is most important that the actual internal computations can run in a lock-free way.
Unfortunately, I have currently no time for that. As soon I have time, I can look into it.
Jörg