$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: terekhov (terekhov_at_[hidden])
Date: 2002-01-16 15:20:34
--- In boost_at_y..., "bill_kempf" <williamkempf_at_h...> wrote:
[...]
> > "Constructors
> > 
> >     thread();
> > 
> >  Effects: Constructs a thread object representing the current 
> thread 
> > of
> > execution.
> > 
> >  Postcondition: *this is non-joinable.
> > 
> >  Danger: *this is valid only within the current thread"
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Ahh.  Sorry, I forgot I specified this in the documentation.  This 
> may be an overspecification on my part and easily fixed.  I 
probably 
> specified this to make the Win32 implementation as fast as possible.
Do you mean GetCurrentThread pseudo handle?
The following is not that much slower and is 
thread-shareable calling DuplicateHandle 0/1 
times only:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/pthreads/misc.c?
rev=1.40&content-type=text/x-cvsweb-markup&cvsroot=pthreads-win32
int
pthread_equal (pthread_t t1, pthread_t t2)
     /*
      * ------------------------------------------------------
      * DOCPUBLIC
      *      This function returns zero if t1 and t2 are equal, else
      *      returns nonzero
      *
      * PARAMETERS
      *      t1,
      *      t2
      *              references to an instances of thread_t
      *
      *
      * DESCRIPTION
      *      This function returns nonzero if t1 and t2 are equal, 
else
      *      returns zero.
      *
      * RESULTS
      *              non-zero        if t1 and t2 refer to the same 
thread,
      *              0               t1 and t2 do not refer to the 
same thread
      *
      * ------------------------------------------------------
      */
{
  int result;
  /*
   * We also accept NULL == NULL - treating NULL as a thread
   * for this special case, because there is no error that we can 
return.
   */
  result = ( ( t1 == t2 ) && ( t1 == NULL || ( t1->thread == t2-
>thread ) ) );
  return (result);
}                               /* pthread_equal */
pthread_t
pthread_self (void)
     /*
      * ------------------------------------------------------
      * DOCPUBLIC
      *      This function returns a reference to the current running
      *      thread.
      *
      * PARAMETERS
      *      N/A
      *
      *
      * DESCRIPTION
      *      This function returns a reference to the current running
      *      thread.
      *
      * RESULTS
      *              pthread_t       reference to the current thread
      *
      * ------------------------------------------------------
      */
{
  pthread_t self;
#ifdef _UWIN
        if(!ptw32_selfThreadKey)
                return(NULL);
#endif
  self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);
  if (self == NULL)
    {
      /*
       * Need to create an implicit 'self' for the currently
       * executing thread.
       */
      self = ptw32_new();
      if (self != NULL)
        {
          /*
           * This is a non-POSIX thread which has chosen to call
           * a POSIX threads function for some reason. We assume that
           * it isn't joinable, but we do assume that it's
           * (deferred) cancelable.
           */
          self->implicit = 1;
          self->detachState = PTHREAD_CREATE_DETACHED;
          self->thread = GetCurrentThreadId ();
#ifdef NEED_DUPLICATEHANDLE
          /* 
           * DuplicateHandle does not exist on WinCE.
           *
           * NOTE:
           * GetCurrentThread only returns a pseudo-handle
           * which is only valid in the current thread context.
           * Therefore, you should not pass the handle to
           * other threads for whatever purpose.
           */
          self->threadH = GetCurrentThread();
#else
          if( !DuplicateHandle(
                               GetCurrentProcess(),
                               GetCurrentThread(),
                               GetCurrentProcess(),
                               &self->threadH,
                               0,
                               FALSE,
                               DUPLICATE_SAME_ACCESS ) )
            {
              free( self );
              return (NULL);
            }
#endif
        }
      pthread_setspecific (ptw32_selfThreadKey, self);
    }
  return (self);
}                               /* pthread_self */
regards,
alexander.