Re: pg_threads.h take II

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: dbryan(dot)green(at)gmail(dot)com, 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:13:37
Message-ID: a2d7b84b-7051-4aec-a18e-00c7b658f252@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-07-06 21:23:42 Re: Can we get rid of TerminateThread() in pg_dump?
Previous Message Heikki Linnakangas 2026-07-06 21:11:54 Re: Can we get rid of TerminateThread() in pg_dump?