cysignals icon indicating copy to clipboard operation
cysignals copied to clipboard

cysignals is not thread-safe

Open jdemeyer opened this issue 9 years ago • 7 comments

It would be nice if cysignals would support multi-threading. This would be useful for use with Python's threading module or with Cython's parallel features.

jdemeyer avatar Feb 17 '16 19:02 jdemeyer

Interesting read: http://www.dabeaz.com/python/GIL.pdf

jdemeyer avatar Feb 17 '16 20:02 jdemeyer

I'd be interested in helping to work on this. I've spent some time in Python's threading code, though really that's less important than just getting it right at the C level.

embray avatar Apr 21 '17 09:04 embray

The problem is that I want the following properties:

  1. Correctness
  2. Portability
  3. Speed

This is a classic case of "pick any two" (the current implementation has properties 2 and 3).

jdemeyer avatar Apr 21 '17 09:04 jdemeyer

Right. For a multi-threaded approach I suspect what we're really going to have to have are just completely separate implementations that can be enabled/disabled at compile time and/or runtime.

embray avatar Apr 21 '17 10:04 embray

I'd like to focus on the case where there is a single thread in Python, but possibly multiple threads in the code guarded by sig_on(). This is probably the most typical use case for cysignals.

jdemeyer avatar Mar 06 '19 09:03 jdemeyer

Apparently on FreeBSD one cannot link cysignals against multithreaded Pari, it just does not work, see https://trac.sagemath.org/ticket/28242#comment:48

[cysignals-1.10.2]     cc -pthread -shared -L/usr/local/lib -fstack-protector-strong -L/usr/ports/math/sage/work/stage/usr/local/lib -Wl,-rpath,/usr/ports/math/sage/work/stage/usr/local/lib -L/usr/local/llvm90/lib -L/usr/local/lib -Wl,-rpath=/usr/local/lib/gcc9 -L/usr/local/lib/gcc9 -B/usr/local/bin -L/usr/local/lib -fstack-protector-strong -O2 -pipe -DLIBICONV_PLUG -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -DLIBICONV_PLUG -I/usr/local/include -isystem /usr/local/include -Wp,-U_FORTIFY_SOURCE build/temp.freebsd-12.1-STABLE-amd64-3.7/build/src/cysignals/signals.o -L/usr/local/lib -lpython3.7m -o build/lib.freebsd-12.1-STABLE-amd64-3.7/cysignals/signals.so -lpari -lomp -pthread -L/usr/local/lib
[cysignals-1.10.2]     /usr/local/bin/ld: PARI_SIGINT_block: TLS definition in /usr/local/lib/libpari.so section .tbss mismatches non-TLS reference in build/temp.freebsd-12.1-STABLE-amd64-3.7/build/src/cysignals/signals.o
[cysignals-1.10.2]     /usr/local/bin/ld: /usr/local/lib/libpari.so: error adding symbols: bad value

dimpase avatar Apr 27 '20 04:04 dimpase

I opened issue 122 before checking this. It turns out that struct_signals.h won't even compile with -fopenmp in some instances.

While sig_on()/sig_off() isn't thread safe, I didn't notice any problem with sig_check().

kliem avatar Jan 31 '21 17:01 kliem