[Mlir-commits] [mlir] [MLIR:Python] Fix race on PyOperations. (PR #139721)
Maksim Levental
llvmlistbot at llvm.org
Wed May 14 08:39:22 PDT 2025
================
@@ -725,19 +733,27 @@ class PyOperation : public PyOperationBase, public BaseContextObject {
/// parent context's live operations map, and sets the valid bit false.
void erase();
- /// Invalidate the operation.
- void setInvalid() { valid = false; }
-
/// Clones this operation.
nanobind::object clone(const nanobind::object &ip);
+ /// Invalidate the operation.
+ void setInvalid() {
+ nanobind::ft_lock_guard lock(getContext()->liveOperationsMutex);
+ setInvalidLocked();
+ }
+ /// Like setInvalid(), but requires the liveOperations mutex to be held.
+ void setInvalidLocked() { valid = false; }
----------------
makslevental wrote:
> has the nice property of being present if and only if we are in GIL-disabled mode.
seems special enough to me. we can file this as a `TODO` and just do the tedious thing instead for now (rename the affected methods).
https://github.com/llvm/llvm-project/pull/139721
More information about the Mlir-commits
mailing list