←back to thread

196 points bovem | 3 comments | | HN request time: 0.631s | source
Show context
jdeaton ◴[] No.41144130[source]
does it have a GIL
replies(2): >>41144305 #>>41145309 #
galdosdi ◴[] No.41144305[source]
idk but Jython didn't. So I don't think there's anything inherent in the language outside of CPython that calls for it.
replies(3): >>41144842 #>>41145702 #>>41146871 #
Tuna-Fish ◴[] No.41145702[source]
The complete semantics of Python object lifetime are expensive to implement in a compatible manner without a GIL. Jython got around this by not doing it, making it not fully compatible (yes, people do depend on objects being eagerly freed), just using the JVM GC instead. If you do want full compatibility, the choice is between single-threaded performance and parallelism.
replies(1): >>41146066 #
1. radarsat1 ◴[] No.41146066[source]
> yes, people do depend on objects being eagerly freed

I get that this must be one aspect of the necessity of the GIL but I mean, C++ also has eager free behavior due to RAII and threads are working fine there, as long as you know what you're doing. Perhaps that's the rub though, it's pretty easy to crash/deadlock in C++ and we blame the programmer rather than the language.

replies(1): >>41147300 #
2. nostrademons ◴[] No.41147300[source]
Idiomatic C++ relies much more heavily on ownership and not so much on refcounting. If you have code that's a rat's nest of shared_ptr, it's going to perform very poorly in a multithreaded environment. But that's why any C++ guru will tell you to not make a rat's nest of shared_ptr. When refcounting is commonly used in C++, like with GUI code or dependency graphs of network requests, it's usually in non-performance-critical sections.

In Python, by contrast, all variables default to object references, and so nearly everything you do involves updating a refcount.

replies(1): >>41148337 #
3. radarsat1 ◴[] No.41148337[source]
Right so you're saying that Python's need to keep ref counts is what leads to the need for synchronizing updates, leading to the need for a lock, more or less. Which is only needed in C++ if you program in a kind of Python style. Makes sense and is a good point.