Thread.interrupt()
Boehm, Hans
hans_boehm@hp.com
Sat Apr 1 00:00:00 GMT 2000
I agree that you can invent a protocol that will make it possible to
interrupt a thread blocked on I/O by closing a file descriptor (assuming
that closing a file descriptor actually terminates a read). The crucial
problem with this is that at least every class in the system that performs
blocking I/O has to play by these rules. In most cases, you won't have
control over all of them. And those implemented by others won't play by
your rules. For example, I'd be surprised if something like
java.net.URLConnection gave access to all file descriptors it might wait on,
e.g. for name lookups.
Thread.interrupt() was intended to provide a general solution to this
problem, effectively by standardizing the protocol (and making it a bit more
general in the process).
Hans
-----Original Message-----
From: Miles Sabin [ mailto:msabin@cromwellmedia.co.uk ]
Sent: Wednesday, March 15, 2000 5:51 AM
To: java-discuss@sourceware.cygnus.com
Subject: RE: Thread.interrupt()
Boehm, Hans wrote,
> Thread A decides it wants to cancel thread B. How can it
> close the file descriptor, which is located in a local
> variable 28 frames down in B's stack? Even if B cooperated,
> and put the file descriptor in some public place, there's no
> obvious place to put it. It can't put it in a fixed global
> place, since C and D might overwrite it.
I don't see this as a problem specific to interruptable IO or
even concurrency. Similar issues might arise in, for example,
(syntactic) error handling/recovery in a recursive descent
parser, or any number of other scenarios where the stack is
used to encode an objects state.
In fact, it looks like a straightforward software design issue
to me. Effectively what you're saying is that cancellation is a
first class aspect of the behaviour associated with thread B.
That being so it should be exposed at the interface level and
then implemented in whatever the appropriate way is. For a
simple example: B's Runnable instance might have a register()
method to allow the 28-frame-down FD to be associated with the
the state of thread B as a whole; and a cancel() method
accessible to A which closes it.
Cheers,
Miles
--
Miles Sabin Cromwell Media
Internet Systems Architect 5/6 Glenthorne Mews
+44 (0)20 8817 4030 London, W6 0LJ, England
msabin@cromwellmedia.com http://www.cromwellmedia.com/
More information about the Java
mailing list