gap icon indicating copy to clipboard operation
gap copied to clipboard

HPC-GAP race condition in cyclotomics code

Open fingolfin opened this issue 3 years ago • 2 comments

The kernel function Cyclotomic uses static local variables:

    static UInt         lastN;          /* remember last n, dont recompute:  */
    static UInt         phi;            /* Euler phi(n)                    */
    static BOOL         isSqfree;       /* is n squarefree?                */
    static UInt         nrp;            /* number of its prime factors     */

This is not thread safe. As a result, if two threads performs cyclotomics computations concurrently, the results may be wrong. (I've not tried to write a reproducer, but the issue is fairly obvious).

I guess one way to fix it might be to use C11's _Thread_local. Or to use our own thread local storage system

fingolfin avatar Oct 13 '22 21:10 fingolfin

And it was there all the time since HPC-GAP appearance?

By the way, one can also use C++'s thread_local and compile with a C++ compiler.

dimpase avatar Oct 17 '22 15:10 dimpase

If we use C11, is pr #5547 good enough?

nskeip avatar Dec 17 '23 16:12 nskeip