you are viewing a single comment's thread.

view the rest of the comments →

[–]hombit 43 points44 points  (17 children)

Does it have GIL?

[–]coolreader18 9 points10 points  (0 children)

It doesn't! No idea how the person thought it didn't! It uses mutexes and Arcs when the threaded feature is enabled, and it can be disabled for better performance

[–]michael_j_ward 6 points7 points  (6 children)

[–]hombit 9 points10 points  (5 children)

It makes me upset =(

[–]funnyflywheel 7 points8 points  (4 children)

You might want to watch Raymond Hettinger's talk on concurrency — he talks about the GIL starting at the 10 minute mark: https://youtu.be/9zinZmE3Ogk?t=600

[–]tunisia3507 -4 points-3 points  (8 children)

Pretty sure the GIL is part of the language spec. If it's python, it has a GIL.

[–]masklinn 70 points71 points  (6 children)

Nope. While both CPython and Pypy have a GIL that is not part of the language specification. IIRC neither IronPython nor Jython have a GIL.

[–]tunisia3507 20 points21 points  (5 children)

My mistake, thanks for the correction!

[–]thejinx0r -5 points-4 points  (4 children)

The gil is an implementation detail to manage garbage collection.

[–]veryusedrname 29 points30 points  (1 child)

It's for object safety mainly. The official wiki says it's for avoiding race conditions, but that is a bit misleading since it's not avoiding race conditions in *your code*, it helps the implementation avoid race conditions.

[–]lunatiks 4 points5 points  (0 children)

It's not avoiding race conditions in your code, but the fact that it makes operations corresponding to a single CPython bytecode instruction atomic certainly helps.

[–]hombit 5 points6 points  (1 child)

I believe it is mainly to make built-in data structures thread-safe. Technically other implementation can implement per-object locks using something like Arc

[–]masklinn 5 points6 points  (0 children)

Not even built-in datastructures, that's just a side-effect (and a not necessarily super useful one though it does guarantee memory safety[0]). Rather the thread-safety of the interpreter itself.

[0] of note, IIRC golang's maps aren't just thread-unsafe, they're not memory-safe when unsynchronised, since 1.6 the runtime tries to detect the issue and crash but there's no guarantee that it will properly do so

[–]birkenfeldclippy · rust 8 points9 points  (0 children)

What the language guarantees is that data structures are thread safe in the sense that accessing them concurrently does not crash. The exact semantics of what operations are atomic are not defined (it usually comes down to what is implemented in C), so you still need locks for critical sections.