Cross-thread locks can starve if there is a hub #1744
Labels
Type: Bug
Identified as a bug; needs a code change to fix
Type: Enhancement
We can do better through adding this
(This came up while I was pondering and testing #1735.)
Consider this code, which has one native thread spinning on acquiring and releasing a lock, while another thread just wants to acquire it once. The spinning thread is started before the other thread.
When run directly, it works:
When run using native locks, it works:
However, as soon as one or both of the background threads gets a gevent hub, it fails; the spinning thread monopolizes the lock and the parked thread never gets a chance:
(The vast majority of the time, it just spins forever. Sometimes, rarely, it actually does appear to work; I think this is a race condition in the startup code.)
This is due to how the thread parks itself when it has a hub, and this happens if just one thread (either one!) has a hub, or they both do.
With the work in #1743, we're probably close to being able to handle this.
The text was updated successfully, but these errors were encountered: