cvs commit: projects/csup mux.c

Maxime Henrion mux at FreeBSD.org
Mon Feb 20 18:49:59 PST 2006


mux         2006-02-21 02:49:59 UTC

  FreeBSD projects repository

  Modified files:
    csup                 mux.c 
  Log:
  Fix a race related to the multiplexer shutdown.  Since mux_shutdown()
  needs to unlock the multiplexer mutex to cancel the sender and receiver
  threads and that it was setting the "closed" status before unlocking,
  another thread calling mux_shutdown() could return immediately, even
  though the other thread doing the shutdown has not finished cancelling
  the threads.
  
  The net effect to this race was that if the receiver thread got his
  connection closed and thus called mux_shutdown(), it would wake up the
  worker threads and, in turn, the main thread waiting on them, and the
  main thread would eventually call mux_close() before the receiver
  thread has finished killing the sender one, freeing the multiplexer
  data structures under its feet.
  
  To fix this, have both a "closing" and a "closed" flag.  The "closing"
  flag means that someone is taking care of the shutdown, but he has not
  finished it.  The "closed" flag means the multiplexer is really closed
  now.
  
  If a thread calls mux_shutdown() while the multiplexer is in the
  "closing" state, it will wait on the "done" condition variable so that
  it don't return before the multiplexer is fully closed.  And if we are
  the thread doing the shutdown, we relock the multiplexer, set the
  "closed" flag and signal the waiting threads only when we are done
  killing the threads.
  
  Revision  Changes    Path
  1.66      +17 -2     projects/csup/mux.c


More information about the cvs-projects mailing list