public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Ross Johnson <rpj@ise.canberra.edu.au>
To: Chris Seaton <chris@chrisseaton.com>
Cc: pthreads-win32@sources.redhat.com
Subject: Re: How is pthread_self() implemented?
Date: Mon, 01 Sep 2003 04:33:00 -0000	[thread overview]
Message-ID: <3F52CBD0.2070205@ise.canberra.edu.au> (raw)
In-Reply-To: <1062352346.4373.7.camel@william>

Chris Seaton wrote:

>I'm writing my own (very lightweight) threading library for Windows and
>POSIX threads. There are reasons why I can't use pthreads-win32, but
>they aren't important here. I'm currently implementing a ThisThread()
>routine. With POSIX threads I simply call pthread_self(), but I'm stuck
>for Windows.
>
>Originally I called GetCurrentThread(), but that returns a pseudo
>handle, so I call DuplicateHandle(), as this pthreads-win32 library
>uses.
>
>However, DuplicateHandle() creates a new handle every time it is called,
>so I can't compare them. Basically
>
>ThisThread() != ThisThread()
>
>How does the pthreads-win32 library solve this problem?
>  
>
Pthreads-win32 keeps a POSIX thread struct in which it stores the handle 
returned by the original Win32 CreateThread(). The pointer to the POSIX 
struct is kept in TLS (TSD) so that other pthread library functions can 
refer to that struct.

John Bossom's original design also allows for pre-existing Win32 threads 
to use any POSIX routines, and therefore fully interact with POSIX 
threads, by creating a one-time-only on-the-fly detached POSIX thread 
handle for the Win32 thread. In this case, the library uses 
DuplicateHandle(), which is sufficient for our purposes.

This is the logic you'll see in pthread_self.c at the following URL (all 
one line):
http://sources.redhat.com/cgi-bin/cvsweb.cgi/pthreads/pthread_self.c?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=pthreads-win32

Regards.
Ross


  reply	other threads:[~2003-09-01  4:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-31 17:52 Chris Seaton
2003-09-01  4:33 ` Ross Johnson [this message]
2003-09-01  4:41   ` Will Bryant
2003-09-01  7:22     ` Ross Johnson
2003-09-01 15:49       ` Ross Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F52CBD0.2070205@ise.canberra.edu.au \
    --to=rpj@ise.canberra.edu.au \
    --cc=chris@chrisseaton.com \
    --cc=pthreads-win32@sources.redhat.com \
    --cc=rpj@callisto.canberra.edu.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).