In AOLserver 3.3+ad13, when I use the Ns_Tls* thread local storage
functions in my C code, when I call Ns_TlsAlloc do I need to surround
it with calls to Ns_MasterLock and Ns_MasterUnLock?

I am kind of confused, as a lot of the code in AOLserver DOES use
Ns_MasterLock like that, but some of it does not, and nothing in the
docs suggest that you need to or should.

E.g., aolserver/nsd/adp.c and aolserver/nsd/dbinit.c both use
Ns_MasterLock.  aolserver/thread/test.c seems to sometimes use it
sometimes not.  nscache/tclcache.c definitely does not use it.

My code showing how I'm using the Ns_Tls stuff is below.  Thanks for
any advice you can give me!


/* In mymodule.h: */
static Ns_Tls myflag_p_tlsKey = NULL;

/* In mymodule.c: */
static int
BB_MyFlag_TlsGet()
{
   int myflag_p = NS_FALSE;

   /*
    * Typically, the Thread Local Storage "value" is used as a pointer
    * to our own malloc'd storage.  But since we only need to store a
    * single boolean value per thread, we use the TLS "value" directly
    * as our boolean integer value, NOT as a pointer.
   */

   if (myflag_p_tlsKey == NULL) {
      Ns_MasterLock();
      if (myflag_p_tlsKey == NULL) {
         Ns_TlsAlloc(&myflag_p_tlsKey, NULL);
         Ns_TlsSet(&myflag_p_tlsKey, myflag_p);
      }
      Ns_MasterUnlock();
   }

   myflag_p = (int) Ns_TlsGet(&myflag_p_tlsKey);
   return myflag_p;
}

--
Andrew Piskorski <[EMAIL PROTECTED]>
http://www.piskorski.com

Reply via email to