jigar-joshi / libjingle

Automatically exported from code.google.com/p/libjingle
0 stars 0 forks source link

a potential bug in MessageQueue::Get() and Quit() #83

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The pseudo code of the two methods:

void MessageQueue::Quit() {
  fStop_ = true;
  ss_->WakeUp();
}

MessageQueue::Get(...) {
  while (true) {
    ...
    if (fStop_) break;
    ... // <== point A
    ss_->Wait(cmsNext, process_io);
    ...
  }
}

The following scenario would cause Get() to miss the request from Quit():

o Thread 1 calls Get()
o When thread 1 runs to point A, Thread 2 calls Quit()
o Thread 2 finishes Quit() before thread 1 enters ss_->Wait()

Proposed solution: instead of fStop_, use a poison message to signal the 
message queue.

Original issue reported on code.google.com by wang.wei...@gmail.com on 2 Nov 2010 at 4:37

GoogleCodeExporter commented 9 years ago
This code seems to fix it. 

Original comment by luke.we...@gmail.com on 4 Oct 2012 at 9:24

Attachments:

GoogleCodeExporter commented 9 years ago
This is an updated diff. I accidentally didn't break out of the loop, causing 
thing to not exit correctly when waiting on a stop on a thread.

Original comment by luke.we...@gmail.com on 5 Nov 2012 at 11:16

Attachments:

GoogleCodeExporter commented 9 years ago
You would also need to do this in DoDelayedPost as well.

Original comment by luke.we...@gmail.com on 14 Nov 2012 at 4:56