Making sense of TSD

Mike Hommey mh+jemalloc at glandium.org
Wed Apr 11 12:15:33 PDT 2012


On Wed, Apr 11, 2012 at 09:12:29PM +0200, Mike Hommey wrote:
> On Wed, Apr 11, 2012 at 09:08:42PM +0200, Mike Hommey wrote:
> > On Wed, Apr 11, 2012 at 12:05:05PM -0700, Jason Evans wrote:
> > > On Apr 11, 2012, at 10:22 AM, Mike Hommey wrote:
> > > > I'm trying to make sense of the tsd implementation without __thread,
> > > > which would seem to fit the tls model on windows. But I don't see
> > > > why the wrapper struct is needed at all. The first thing that
> > > > bothers me is that the isstatic == true case is set to abort on
> > > > opt_abort, yet is supported. And it doesn't seem very obvious why
> > > > initialized is needed.
> > > 
> > > The wrapper struct is needed with pthreads TSD because
> > > pthread_[gs]etspecific() only operate on (void *) pointers.  Thus it's
> > > impossible to store more than a pointer-sized item with pthreads TSD
> > > unless that pointer refers to an allocated structure.  I don't
> > > remember the details of Windows's TLS/TSD API; if it can store any
> > > type/structure, then no wrapper struct is needed.
> > 
> > Well, the void* pointer could just point to whatever structure you want
> > to store, instead of having a struct containing two bools which
> > usefulness I'm doubtful about, and a pointer to that allocated structure.
> > At least it seems so. That was my question.
> 
> In fact, I don't see why it needs to be so different from the
> JEMALLOC_TLS implementation, in which the tls variable is just a
> shortcut to avoid using pthread_getspecific for each tsd_get. But maybe
> I'm missing something.

(and allocated at thread creation, but that's not really a problem)

Mike

PS: Sorry for the mail flood.



More information about the jemalloc-discuss mailing list