Skip to content

Commit dc68d22

Browse files
committed
Acquire interop lock in buffer release thread
1 parent c812b74 commit dc68d22

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewBuiltins.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,17 @@ public void execute(PythonContext context) {
134134
ManagedBuffer buffer = reference.getManagedBuffer();
135135
// Managed buffers should be released directly in the reference queue thread
136136
assert buffer.isForNative();
137-
CExtNodes.PCallCapiFunction.getUncached().call(NativeCAPISymbols.FUN_PY_TRUFFLE_RELEASE_BUFFER, buffer.getBufferStructPointer());
137+
boolean shouldLock = !context.getSingleThreadedAssumption().isValid();
138+
if (shouldLock) {
139+
context.acquireInteropLock();
140+
}
141+
try {
142+
CExtNodes.PCallCapiFunction.getUncached().call(NativeCAPISymbols.FUN_PY_TRUFFLE_RELEASE_BUFFER, buffer.getBufferStructPointer());
143+
} finally {
144+
if (shouldLock) {
145+
context.releaseInteropLock();
146+
}
147+
}
138148
}
139149
}
140150

0 commit comments

Comments
 (0)