This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3] New functions pthread_[sg]etattr_default_np for default thread attributes


On Tue, Jun 11, 2013 at 05:06:01PM -0700, Roland McGrath wrote:
> > +    {
> > +      /* Is this the best idea?  On NUMA machines this could mean
> > +         accessing far-away memory.  */
> > +      iattr = &__default_pthread_attr;
> > +      lll_lock (__default_pthread_attr_lock, LLL_PRIVATE);
> > +    }
> 
> Taking the lock around so much code is very scary.  Even if you have no
> bugs leading to error paths that fail to unlock, it is unnecessary
> serialization.  Except for the cpuset pointer, it would be trivial just to
> make a local stack copy of the global while locked, and then use that.

I didn't think too much of this in terms of serialization because the
only programs that will actually keep writing to the default
attributes would suffer from lock contention.  However, I realize now
that there could be contention for reading default values too, and
also serialization between two threads on creation, which is bad.

I'll make a local deep copy on stack.  Allocating a copy of the cpuset
would definitely be better than serializing thread creation.  Maybe I
could update the code in 2.19 to use read/write locks so that only
writing causes contention.  I've wondered if an RCU-type mechanism
would be useful in glibc - maybe this is one such case.

> I have to run now and I haven't reviewed the test case yet.

Thanks for the review.  I hope to have an updated version ready by the
time you wake up.  My test case had a few minor points that I realized
later that I didn't like (mostly related to error reporting in the
RETURN_IF_FAIL macro), so I'll be updating that too.

Siddhesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]