Commit 1abefda
authored
Fix a data race in nb_meta_cache initialization. (#1301)
We must not overwrite nb_meta_cache if it was already set.
In JAX's use of nanobind we have several module that all share the same
definition of nb_internals. We observed the following data race when
updating to v2.12.0 under Python 3.14t:
* thread t1 imports a nanobind module, which sets nb_meta_cache
unconditionally.
* thread t2 calls nb_type_check, which reads nb_meta_cache.
Even though t1 is overwriting nb_meta_cache with the exact same value it
already had, this is still a data race and therefore undefined behavior.
However there's an easy fix: just don't set nb_meta_cache the second
time if it's already set correctly.1 parent 7d13bfc commit 1abefda
1 file changed
+9
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
462 | 464 | | |
463 | 465 | | |
464 | 466 | | |
| |||
486 | 488 | | |
487 | 489 | | |
488 | 490 | | |
489 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
490 | 494 | | |
491 | 495 | | |
492 | 496 | | |
| |||
510 | 514 | | |
511 | 515 | | |
512 | 516 | | |
513 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
514 | 520 | | |
515 | 521 | | |
516 | 522 | | |
| |||
0 commit comments