Re: pg_threads.h take II - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: pg_threads.h take II
Date
Msg-id a2d7b84b-7051-4aec-a18e-00c7b658f252@iki.fi
Whole thread
In response to Re: pg_threads.h take II  (dbryan.green@gmail.com)
Responses Re: pg_threads.h take II
List pgsql-hackers
On 07/07/2026 00:01, dbryan.green@gmail.com wrote:
> On 7/6/26 3:48 PM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>> On 06/07/2026 15:09, Thomas Munro wrote:
>>> +#ifdef WIN32
>>> +
>>> +    /*
>>> +     * Retrieve handle passed here by pg_thrd_create() before
>>> allowing this
>>> +     * thread to run.  (pg_thrd_current() can't use CurrentThread(),
>>> because
>>> +     * that returns a pseudo-handle with the same value in all threads.)
>>> +     */
>>> +    Assert(start_info->self);
>>> +    my_thrd_handle = start_info->self;
>>> +#endif
>>
>> Does that refer to the GetCurrentThreadId() function? We use that in a
>> few places currently.
>>
>> How can it return the same value in all threads, isn't that completely
>> useless? And does that mean all our current uses of it are broken?
>
> GetCurrentThread() not GetCurrentThreadId()...  GetCurrentThread()
> returns a special sentinel handle (-2) that when passed to another
> Win32 function causes the kernel to resolve to whatever thread made
> the call....
> 
> So, no-- not broken.

Ah gotcha. Could we use GetCurrentThreadId() here then? (I have no 
problem with the way it's currently done in the patch either though, 
just curious)

- Heikki




pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Can we get rid of TerminateThread() in pg_dump?
Next
From: Heikki Linnakangas
Date:
Subject: Re: Can we get rid of TerminateThread() in pg_dump?