Quoting Samuel Thibault (2014-05-13 00:28:38)
> Justus Winter, le Mon 12 May 2014 12:05:42 +0200, a écrit :
> > -  pthread_mutex_lock (&_ports_lock);
> >    pthread_mutex_lock (&_ports_htable_lock);
> >  
> >    if (_ports_htable.nr_items == 0)
> > @@ -60,13 +59,12 @@ _ports_bucket_class_iterate (struct port_bucket *bucket,
> >        if ((bucket == NULL || pi->bucket == bucket)
> >            && (class == NULL || pi->class == class))
> >       {
> > -       pi->refcnt++;
> > +       refcounts_ref (&pi->refcounts, NULL);
> >         p[n] = pi;
> >         n++;
> >       }
> >      }
> >    pthread_mutex_unlock (&_ports_htable_lock);
> > -  pthread_mutex_unlock (&_ports_lock);
> 
> Mmm, just to warn (I'm not sure I'll get the time soon to review these
> changes), this kind of change needs a lot of making sure we see the
> whole picture: quite often taking the mutex is not only to protect
> the reference counting, but also to make that coherent with other
> reads/writes, and thus only an atomic operation is not enough. As an
> example, here we would want to make sure other threads see that we have
> acquired a reference, before recording the pointer and doing something
> else.  Keeping the mutex is more than we need, but we need to make sure
> we still synchronize enough with the rest of the code.

I'm aware of that.  Note that _ports_complete_deallocate aquires the
_ports_htable_lock and checks if someone reacquired a reference
through the hash table.

Justus

Reply via email to