Message327693
> What would make it not reentrant-safe?
Probably the most obvious example of a non-reentrant-safe operation is taking a lock. It's very natural to write code like:
def call_soon(...):
with self._call_soon_lock:
...
but now imagine that inside the body of that 'with' statement, a signal arrives, so the interpreter pauses what it's doing to invoke the signal handler, and the signal handler turns around and invokes call_soon, which tries to acquire the same lock that it already holds → instant deadlock.
And this rules out quite a few of the tools you might normally expect to use in thread-safe code, like queue.Queue, since they use locks internally.
The reason I think the stdlib's call_soon is OK is that it doesn't perform any blocking operations, and the critical operation is simply 'self._ready.append(...)', which in CPython is atomic with respect to threads/signals/GC. |
|
Date |
User |
Action |
Args |
2018-10-14 07:19:46 | njs | set | recipients:
+ njs, asvetlov, yselivanov |
2018-10-14 07:19:46 | njs | set | messageid: <1539501586.32.0.788709270274.issue34968@psf.upfronthosting.co.za> |
2018-10-14 07:19:46 | njs | link | issue34968 messages |
2018-10-14 07:19:45 | njs | create | |
|