23 Commits

Author SHA1 Message Date
Peter Edwards 04b9a20e94 Block signal delivery to numexpr-spawned threads
Applications that embed python, or use platform-specific python
extensions, may use signals in a way that is currently affected by
`numexpr` launching threads.

For example, it is not uncommon for an application main loop to block
signals when busy, then unblock those signals while waiting for IO.
(see the sigmask argument to `ppoll(2)`)

Signals that arrive during `ppoll(2)` will interrupt the system call,
and allow the application to handle any consequences of that signal
arriving.  Normally (in a single threaded process), on delivery of an
externally generated signal such as SIGALRM, SIGCHLD, SIGIO the main
loop will be awoken. IF the thread is otherwise busy, then the signal
will be maintained as pending, and will be delivered when the
application next enters its idle state with `ppoll` again.

`numexpr` creates threads on import. Such threads inherit their signal
masks from the thread that creates them, and, because the import will
generally happen early in the lifetime of a program, all signals are
nominally unblocked in the `numexpr` threads.

Later, if the "main" thread is running with signals blocked when a
signal is sent to the process, the kernel will deliver it to another
thread in the process if it is not currently blocking that  signal,
namely, one of the `numexpr` threads.

This means that by creating threads with open signal masks, `numexpr` is
potentially interfering with the normal operation of programs that are
otherwise non-threaded.

Instead, we should block all signals before starting numexpr threads,
and then restore the signal mask as it was, so the `numexpr` threads do
not participate in signal delivery and processing.

Signed-off-by: Peter Edwards <peadar@arista.com>
2023-05-23 17:40:49 +01:00
Robert McLeod 99ddb12b18 Remove support for Python 2.7 and 3.5; add support for Python 3.10 2021-11-08 19:54:18 -08:00
Robert McLeod c8c27a930b Add a utility function get_num_threads 2020-09-23 18:44:31 -07:00
Robert McLeod c7efad14cf Remove set_vml_num_threads(1) from __init__.py; Add export for use_vml and __BLOCK_SIZE1__ in interpreter.cpp` 2020-01-26 15:07:33 -08:00
Nigel Delaney 17d0b1928d Add Getter for VML Thread Count
Adds `get_vml_num_threads` to match `set_vml_num_threads`
2020-01-13 18:38:20 -08:00
Eugene Toder 004f00f41c Fix memory leak in add_symbol. 2019-06-14 11:15:33 -04:00
Robert McLeod 422de133fd Move init_threads() protection inside the function; rename threads_ready -> barrier_passed to avoid confusion with threads init vars 2018-07-12 10:51:30 -07:00
Mark Dickinson 79232c0632 Fix: allow for spurious wakeup calls from pthread_cond_wait. 2018-07-12 13:28:32 +01:00
Robert McLeod 09959bb943 Update MKL path in site.cfg.example; apply code review for MAX_THREADS 2018-04-30 10:35:16 -07:00
Robert McLeod 694a838a5a Control max threads with 'NUMEXPR_MAX_THREADS' environment variable 2018-04-10 11:31:17 -07:00
Oleksandr Pavlyk f81fe92633 MAINT: Update to use current Numpy API
This eliminates numerous warnings like

warning: #warning "Using deprecated NumPy API, disable it by "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
2016-10-10 15:04:55 -05:00
Antoine Pitrou 2baef92b95 Fix crash when evaluate() called from multiple threads 2016-01-20 10:54:27 +01:00
Francesc Alted 70bf71bc5a Undone a 'fix' for a harmless data race. Fixes #185. 2015-10-24 12:03:07 +02:00
Clement Courbet f6462f52c1 Fix harmless data race that triggers false positives in ThreadSanitizer. 2015-06-04 20:36:51 +02:00
Francesc Alted 224ac6f872 MKL_VML -> MKL_DOMAIN_VML because the former is deprecated in MKL 2015-04-14 14:33:28 +02:00
Francesc Alted 6be8ad5dec Using the correct name for mkl_get_version_string() for MKL 11. 2014-01-24 16:29:08 +01:00
Francesc Alted cf22320445 Added support for latest version of MKL 2013-04-14 23:45:39 +02:00
Antonio Valentino 2988ce8a74 Fix module initialization to support both Python 2 and Python 3.
Handling of global_state still needs to be improved.
2012-04-22 11:17:48 +02:00
Antonio Valentino 8e47beca98 Fixed incompatibilities regarding the int/long API 2012-04-15 13:25:04 +02:00
Antonio Valentino b83e68bdb3 Switch from PyString to PyBytes API 2012-04-15 13:18:11 +02:00
Mark Wiebe b8a42cbeec Replace tabs with spaces 2012-03-01 15:37:38 -08:00
Mark Wiebe db92b02ed9 Fix issue 69, wrong result when out is also an input
This doesn't deal with the more general overlapping case.
2012-03-01 15:29:29 -08:00
Mark Wiebe b64ca885eb Split apart interpreter.cpp into more manageable chunks 2012-03-01 14:16:56 -08:00