Re: Advice needed concerning Win32 signals

From: "Magnus Hagander" <mha(at)sollentuna(dot)net>
To: "Thomas Hallgren" <thomas(dot)hallgren(at)home(dot)se>, "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Advice needed concerning Win32 signals
Date: 2005-10-16 16:26:40
Message-ID: 6BCB9D8A16AC4241919521715F4D8BCE92E747@algol.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> 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?

//Magnus

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2005-10-16 16:33:29 Re: slow IN() clause for many cases
Previous Message Greg Stark 2005-10-16 16:03:33 Re: slow IN() clause for many cases