Fix for input readers occasionally dead-locking.

Bernhard and I tracked it down we believe: the thread queue could
deadlock in certain cases. As a fix we tuned the heuristic for telling
if a queue might have input to occasionaly err on the safe side by
flagging "yes", so that processing will proceed.

It's a bit unfortunate to apply this fix last minute before the
release as it could potentially impact performance if the heuristic
fails to often. We believe the chosen parmaterization should be fine ...
This commit is contained in:
Robin Sommer 2013-10-24 18:16:49 -07:00
parent 42c4a51da3
commit c980d1055e
3 changed files with 11 additions and 5 deletions

View file

@ -61,11 +61,13 @@ public:
bool Ready();
/**
* Returns true if the next Get() operation might succeed.
* This function may occasionally return a value not
* indicating the actual state, but won't do so very often.
* Returns true if the next Get() operation might succeed. This
* function may occasionally return a value not indicating the actual
* state, but won't do so very often. Occasionally we also return a
* true unconditionally to avoid a deadlock when both pointers happen
* to be equal even though there's stuff queued.
*/
bool MaybeReady() { return ( ( read_ptr - write_ptr) != 0 ); }
bool MaybeReady() { return (read_ptr != write_ptr) || (random() % 10000 == 0); }
/** Wake up the reader if it's currently blocked for input. This is
primarily to give it a chance to check termination quickly.