tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: How to prevent a mutex being _enter()ed from being _destroy()ed?



Edgar Fuß <ef%math.uni-bonn.de@localhost> writes:

> I know very little about locking so that's probably a stupid question, but:

Don't worry - locking is probably the hardest thing to get right.

> Is there a general scheme/rule/proposal how to prevent a mutex that someone 
> is trying to mutex_enter() from being teared down by someone else calling 
> mutex_destroy() on it during that?

Not really.  Basically it's a bug to destroy a mutex that could possibly
be in use.  So there has to be something else protecting getting at the
mutex that is being destroyed.

> Specifically, I'm trying to understand what should prevent a thread from 
> destroying a socket's lock (by sofree()/soput()) while unp_gc() is trying 
> to acquire that lock.

I would expect (without reading the code) that there would be some lock
on the socket structure (using list here; the type is not the point),
and there would be a

  acquire socket_list lock
  find socket
  lock socket
  unlock sockt_list

or alternatively

  acquire socket_list lock
  find socket
  unlink socket from the list
  unlock sockt_list

  do whatever to the socket

So there has to be a rule about when various things are valid based on
being in various higher-level data structures.  In an ideal world this
rule would be clearly explained in the source code.  Ancient BSD
tradition is not to explain these things :-(

Attachment: signature.asc
Description: PGP signature



Home | Main Index | Thread Index | Old Index