-
Notifications
You must be signed in to change notification settings - Fork 190
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
Thread-safe garbage collection v3 (ReentrantLock version) #1074
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1074 +/- ##
==========================================
- Coverage 67.75% 67.73% -0.02%
==========================================
Files 20 20
Lines 2025 2030 +5
==========================================
+ Hits 1372 1375 +3
- Misses 653 655 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
You might want to try a test-and-test-set pattern: Basically |
Wait isn't that what this already does? Or you mean replacing the |
Yes, use
|
bf2c3eb
to
9dbe833
Compare
Done! |
(Edit: I implemented this as it seems the safer option. Not sure what happens when two threads try to write Old: do we need to make the mutable struct PyBuffer
buf::Py_buffer
PyBuffer() = begin
b = new(Py_buffer(C_NULL, PyPtr_NULL, 0, 0,
0, 0, C_NULL, C_NULL, C_NULL, C_NULL,
C_NULL, C_NULL, C_NULL))
finalizer(pydecref, b)
return b
end
end which references: function pydecref(o::PyBuffer)
# note that PyBuffer_Release sets o.obj to NULL, and
# is a no-op if o.obj is already NULL
_finalized[] || ccall(@pysym(:PyBuffer_Release), Cvoid, (Ref{PyBuffer},), o)
o
end Not sure if this is needed or not. |
By the way, do you know what the threading advice actually is for the Python C API. Is it only one thread at a time, or only call from the same thread? |
It might be time to drop Python 2.7 CI |
Done! #1075 |
I don't see anything related to multi-threading here https://docs.python.org/3/c-api/refcounting.html. Would they have a particular requirement? |
https://docs.python.org/3/c-api/init.html#non-python-created-threads
|
Ok, we're going to need a redesign here since Julia GC is now multithreaded. Now the question is do we really |
I feel like it would be quite a bit of work to properly incorporate the Python GIL into Julia code. That means you would need to thread-lock every single part of PyCall.jl, no? Thread-locking the garbage collection is the major issue IMO, but it also seems easier to solve (with just this PR)? |
Pinging this thread before my teaching starts (and I get buried in work) :) |
@stevengj , have you had a chance to take a look? |
This is an alternative strategy to make the GC thread-safe compared with #1073 (#883).
@stevengj @mkitti @marius311
My concern with #1073 is whether only allowing GC to run on a particular thread might cause an issue or lag in performing garbage collection. Instead this allows the GC to run on any thread but they must obtain a lock first. This is the logic:
One question I have is: does
islocked
work in a re-entrant context? (Or does it even matter, and I could just use a SpinLock?)