Skip to content

GILState.Dispose is safe to be called multiple times #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
GILState.Dispose is safe to be called multiple times
  • Loading branch information
lostmsu committed Feb 1, 2020
commit fcbee0a3011d399d5cf5600cdd8ec76fa5db6922
6 changes: 5 additions & 1 deletion src/runtime/pythonengine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ public static PyScope CreateScope(string name)

public class GILState : IDisposable
{
private IntPtr state;
private readonly IntPtr state;
private bool isDisposed;

internal GILState()
{
Expand All @@ -652,8 +653,11 @@ internal GILState()

public void Dispose()
{
if (this.isDisposed) return;

PythonEngine.ReleaseLock(state);
GC.SuppressFinalize(this);
this.isDisposed = true;
}

~GILState()
Expand Down