Re: Advice needed concerning Win32 signals

From: Thomas Hallgren <thomas(dot)hallgren(at)home(dot)se>
To: mha(at)sollentuna(dot)net
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Advice needed concerning Win32 signals
Date: 2005-10-16 16:56:12
Message-ID: 4352862C.2050809@home.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

mha(at)sollentuna(dot)net wrote:
>> Hi,
>> I'm in the process of securing the PL/Java signal handling routines.
>> Since a multi-threaded JVM is running and a signal can occur
>> at any time in any thread, I need to trap some of them and
>> make sure that they are executed in the main thread. Using
>> Posix signals, this is easy. Here's a sample handler:
>>
>> static void pljavaStatementCancelHandler(int signum) {
>> if(pthread_self() == mainThread)
>> /*
>> * Call original handler
>> */
>> StatementCancelHandler(signum);
>> else
>> /*
>> * Dispatch to main thread.
>> */
>> pthread_kill(mainThread, signum); /* Send it to main
>> thread */ }
>>
>> The mainThread was initialized when the handler was first registered.
>>
>> From looking at the PostgreSQL signal handling routines for
>> Win32, I realize that several threads are involved already.
>> Perhaps all signals are indeed dispatched to the main thread
>> already? I couldn't really figure it out. I need help from
>> someone who knows more about this.
>>
>
> The win32 system itself doesn't have the concept of signals. Therefor,
> the only signals being delivered are those delivered internally between
> the postgresql processes (including those sent manually through pg_ctl).
>
> These "fake signals" are dispatched on the main thread. They are
> received by a worker thread, which will queue them up and set a flag,
> and the main thread then polls this queue and delivers the actual
> signal.
>
> I have *no idea* how pthreads does this. pthread_kill() probably does
> not know about *our* signal emulation layer, but somehow has it's own.
> (as pthreads definitly aren't used in the backend, but I assume you're
> somehow using them for pl/java anyway). Or perhaps that's just not
> necessary and the example was for unix only?
>
Yes, the example is for Posix compliant systems only and it assumes that
the JVM itself base its threading on pthreads.

How is a PostgreSQL process terminated on Windows? Or rather, how is the
concept of die() and quickdie() implemented if it's not based on signals?

Regards,
Thomas Hallgren

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-10-16 16:57:32 Re: slow IN() clause for many cases
Previous Message Tom Lane 2005-10-16 16:43:29 Re: slow IN() clause for many cases