Merge remote-tracking branch 'origin/topic/bernhard/alternative-deadlock-fix'

* origin/topic/bernhard/alternative-deadlock-fix:
  alternative deadlock issue fix.
This commit is contained in:
Robin Sommer 2013-10-25 11:10:08 -07:00
commit 15e72d1422
2 changed files with 17 additions and 5 deletions

View file

@ -82,7 +82,17 @@ double Manager::NextTimestamp(double* network_time)
{ {
MsgThread* t = *i; MsgThread* t = *i;
if ( (*i)->MightHaveOut() && ! t->Killed() ) // We check here if there's something ready to read from the
// queue. Normally the queue will tell us that reliably via
// MightHaveOut() because we keep sending heartbeats that
// will ensure that the method will eventually return true.
// However, when running without network source and without
// any communication, the timer_manager's time will always
// remain at 1.0, which means that heartbeats will never be
// triggered. In that case, we make sure to still process our
// threads from time to time.
if ( ((*i)->MightHaveOut() && ! t->Killed())
|| (timer_mgr->Time() == 1.0 && random() % 10000 == 0) )
return timer_mgr->Time(); return timer_mgr->Time();
} }

View file

@ -63,11 +63,13 @@ public:
/** /**
* Returns true if the next Get() operation might succeed. This * Returns true if the next Get() operation might succeed. This
* function may occasionally return a value not indicating the actual * function may occasionally return a value not indicating the actual
* state, but won't do so very often. Occasionally we also return a * state, but won't do so very often. Note that this means that it can
* true unconditionally to avoid a deadlock when both pointers happen * consistently return false even if there is something in the Queue.
* to be equal even though there's stuff queued. * You have to check real queue status from time to time to be sure that
* it is empty. In other words, this method helps to avoid locking the queue
* frequently, but doesn't allow you to forgo it completely.
*/ */
bool MaybeReady() { return (read_ptr != write_ptr) || (random() % 10000 == 0); } bool MaybeReady() { return (read_ptr != write_ptr); }
/** Wake up the reader if it's currently blocked for input. This is /** Wake up the reader if it's currently blocked for input. This is
primarily to give it a chance to check termination quickly. primarily to give it a chance to check termination quickly.