select and APCs

From: "Magnus Hagander" <mha(at)sollentuna(dot)net>
To: <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: select and APCs
Date: 2004-03-22 20:38:29
Message-ID: 6BCB9D8A16AC4241919521715F4D8BCE17161C@algol.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers-win32

Hi!

Here's a summary of relevant parts of the communications I've had with
Microsoft PSS regarding the issues with select() and APCs:

* Actually it is caused by the fact the Winsock (and also IP Helper)
APIs use APCs in their implementation to receive Network events. This
is not a bug but simply the way Winsock are implemented.

* He has confirmed this is not included in the docs, so it wasn't
somehting we missed.

Regarding workarounds:

* Use a global Boolean variable as you have already said to flag the APC
callback; I discuss with one colleague from the Windows team about
potential side effect and he confirms me it is a valid solution.
Furthermore there is no way to determine that a select call has been
interrupted by a Queued APC callback.

* Create a specific thread to handle the APC callback and prevent
disturbing the Select() call; If a new thread reserves some memory for
its own needs, the memory is only reserved and not committed. Only a few
pages (4KByte) are actually committed at the beginning, and as a
consequence resources should not be a problem here.

Based on my discussions with the PSS guy, I think going with the thread
method is best. This way we fix only the point where we actually have a
problem (instead of working around th eproblem *after* it occured, and
working around it in cases when it does not exist). The resources used
should be insignificant. Also, now the workaround is in force only when
a process dies - if we redefined select() completely it would affect all
other codepaths using select() as well.

I'll send a patch implementing the thread-way of fixing this to the
patches list in a minute. It fixes the problems for me (the
postmaster-can't-shutdown issues).

//Magnus

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Tom.Zschockelt 2004-03-23 13:20:03 connect error
Previous Message Tom Lane 2004-03-22 16:47:32 Re: compile errors