Re: Changeset 0306c5a64775

Robert Ransom <[email protected]> Tue, 10 Jan 2012 10:08:56 +0000
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <CABqy+spj-FUUAQrkdu9GL4y0=u=jO-sD7m0f=fGQbW9wfSJD1w@mail.gmail.com>
On 2012-01-07, Michael Sperber <[email protected]> wrote:
>
> Robert Ransom <[email protected]> writes:

>> Regarding getaddrinfo, I think the Right Thing is to make the Scheme
>> interface to getaddrinfo fill in a placeholder, rather than using the
>> external event system directly as it does now.
>
> OK - it still seems to me the hard part is communicating the information
> from C to Scheme somehow.

The external-events system is broken, both as used by getaddrinfo and
when used with long-lived UIDs.

When a UID is allocated from C for an event, then passed to a Scheme
thread which waits for that UID once, there is a race condition -- if
C signals an event with that UID before Scheme starts waiting for it,
the event will be dropped on the floor, and the Scheme thread will not
be awakened unless and until some other event is allocated the same
UID and is signaled.

When a long-lived UID is allocated for a class of events, and a Scheme
thread waits for that UID repeatedly, there is a different race
condition -- if C signals that UID between the time that Scheme checks
for events previously queued from C and the time that it waits for a
new event, the event signal will be dropped on the floor.

See my event-waiters branch (attached and pushed to hg-git) for a
synchronization primitive which can be used to fix the latter race
condition, provided that the event-waiter is created before C starts
signaling events of a particular class.

To fix the race condition in getaddrinfo-style usage of external
events, we need a way to allocate some sort of event identifier from
Scheme, pass the identifier to C, and pass the result back to Scheme
to be put in a placeholder.


Robert Ransom
s48-2012-01-10-01-event-waiters.hg (application/octet-stream, 3.9 KB) - not displayed