Re: pg_threads.h take II

From: Bryan Green <dbryan(dot)green(at)gmail(dot)com>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Jelte Fennema <postgres(at)jeltef(dot)nl>
Subject: Re: pg_threads.h take II
Date: 2026-07-06 21:28:14
Message-ID: 53afda8f-2ebe-48ab-a055-cd5762941f73@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7/6/2026 4:13 PM, Heikki Linnakangas wrote:
> On 07/07/2026 00:01, dbryan(dot)green(at)gmail(dot)com wrote:
>> On 7/6/26 3:48 PM, Heikki Linnakangas <hlinnaka(at)iki(dot)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
>
I haven't looked at all of the code, but I would assume there is a
WaitFor...Object() somewhere and those only work with actual
handles...not id's. GetCurrentThreadId() returns a dword for id. I'll
look over the patches as well.

--
Bryan Green
EDB: https://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2026-07-06 21:31:06 Re: Collation & ctype method table, and extension hooks
Previous Message Heikki Linnakangas 2026-07-06 21:23:42 Re: Can we get rid of TerminateThread() in pg_dump?