Skip to content

Commit b7bdf98

Browse files
committed
docs: add a message about preparation being not thread safe in documentation
1 parent ef77d13 commit b7bdf98

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

DifferentiationInterface/docs/src/explanation/operators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ op(f, prep, backend, x, [t]) # fast because it skips preparation
117117

118118
!!! warning
119119
The `prep` object is the last argument before `backend` and it is always mutated, regardless of the bang `!` in the operator name.
120+
As a consequence preparation is **not thread safe** and sharing `prep` object between threads may lead to undefined behavior. If you need to run differentiation concurrently, prepare separate `prep` objects for each thread.
120121

121122
### Reusing preparation
122123

DifferentiationInterface/src/docstrings.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ function docstring_prepare(operator; samepoint=false, inplace=false)
2525
The preparation result `prep` is only reusable as long as the arguments to `$operator` do not change type or size, and the function and backend themselves are not modified.
2626
Otherwise, preparation becomes invalid and you need to run it again.
2727
In some settings, invalid preparations may still give correct results (e.g. for backends that require no preparation), but this is not a semantic guarantee and should not be relied upon.
28+
!!! danger
29+
The preparation result `prep` is **not thread safe**. Sharing it between threads may lead to undefined behavior. If you need to run differentiations concurrently, prepare separate `prep` objects for each thread.
2830
2931
When `strict=Val(true)` (the default), type checking is enforced between preparation and execution (but size checking is left to the user).
3032
While your code may work for different types by setting `strict=Val(false)`, this is not guaranteed by the API and can break without warning.

0 commit comments

Comments
 (0)