Skip to content

Commit 1e4f04f

Browse files
committed
Move NUMUSERTYPES thread safety discussion to legacy DType API docs
1 parent 908169c commit 1e4f04f

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

doc/source/reference/c-api/array.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,13 @@ User-defined data types
12641264
registered (checked only by the address of the pointer), then
12651265
return the previously-assigned type-number.
12661266
1267+
The number of user DTypes known to numpy is stored in
1268+
``NPY_NUMUSERTYPES``, a static global variable that is public in the
1269+
C API. Accessing this symbol is inherently *not* thread-safe. If
1270+
for some reason you need to use this API in a multithreaded context,
1271+
you will need to add your own locking, NumPy does not ensure new
1272+
data types can be added in a thread-safe manner.
1273+
12671274
.. c:function:: int PyArray_RegisterCastFunc( \
12681275
PyArray_Descr* descr, int totype, PyArray_VectorUnaryFunc* castfunc)
12691276

doc/source/reference/global_state.rst

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.. _global_state:
22

3-
************
4-
Global state
5-
************
3+
****************************
4+
Global Configuration Options
5+
****************************
66

7-
NumPy exposes global state in legacy APIs and a few import-time,
8-
compile-time, or runtime options which change the global behaviour.
9-
Most of these are related to performance or for debugging purposes and
10-
will not be interesting to the vast majority of users.
7+
NumPy has a few import-time, compile-time, or runtime configuration
8+
options which change the global behaviour. Most of these are related to
9+
performance or for debugging purposes and will not be interesting to the
10+
vast majority of users.
1111

1212

1313
Performance-related options
@@ -70,10 +70,3 @@ and set the ``ndarray.base``.
7070

7171
.. versionchanged:: 1.25.2
7272
This variable is only checked on the first import.
73-
74-
Legacy User DTypes
75-
==================
76-
77-
The number of legacy user DTypes is stored in ``NPY_NUMUSERTPES``, a global
78-
variable that is exposed in the NumPy C API. This means that the legacy DType
79-
API is inherently not thread-safe.

doc/source/user/c-info.beyond-basics.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ specifies your data-type. This type number should be stored and made
268268
available by your module so that other modules can use it to recognize
269269
your data-type.
270270

271+
Note that this API is inherently thread-unsafe. See `thread_safety` for more
272+
details about thread safety in NumPy.
273+
271274

272275
Registering a casting function
273276
------------------------------

0 commit comments

Comments
 (0)