In article [email protected],
Paul B. [email protected] writes:
Raising an exception during a blocking write operation makes it
impossible to know how much data was written.
Similarly, raising an exception during a blocking read operation makes
it impossible to access the data that was read.
It is a very difficult problem.
I don’t try to solve the problem perfectly.
I think the data lost may be acceptable if an asynchronous
event is for termination.
If the purpose is termination, data lost may be happen
anyway. For example, data from TCP is lost if a process
exits before data arrival.
If data lost is acceptable but termination delay is not
acceptable, Thread.blocking_interruptible(klass) { I/O } can
be used.
If data lost is not acceptable but termination delay is
acceptable, Thread.blocking_uninterruptible(klass) { I/O }
can be used.
If data lost and termination delay is not acceptable, it is
difficult. One idea is
Thread.blocking_interruptible(klass) { IO.select } and
nonblocking I/O. But nonblocking I/O causes inherently
partial result. So there should be a read/write buffer. If
termination procedure ignore the read buffer, data lost
occur. If termination procedure flushes the write buffer,
it may blocks. So data lost or termination delay again. It
is the difficult problem.
I hope either data lost or termination delay is acceptable.
If an asynchronous event is used for non-termination, data
lost is not acceptable in general. Assume a procedure is
called for the event. If some delay is acceptable,
Thread.blocking_uninterruptible(klass) { I/O } can be used.
If the delay is also not acceptable, it is the difficult
problem. However if the event is caused by Thread#raise,
I’m not sure why the procedure is not called directly
instead of Thread#raise. If the event is caused by signal,
I have no good idea to do it.
So I think asynchronous events should be used only for
termination. This is why I think exception on blocking
operation is tolerable.