On Tue, 08 August 2000, Scott Stanton wrote:
> <Notes on the Tcl event loop>
Thanks for the information. It seems that multi-threaded Tcl already implemented some
cross-platform thread notification, maybe TclBlend should use something like
Tcl_ThreadAlert() to wake up the event loop. But this function is not available for
non-threaded Tcl. So for single-threaded Tcl, TclBlend still needs to use the current
custom notification system.
> > used in TclBlend is triggering a busy loop on reading from the pipe.
> The
> > similar code in Tcl 8.3.1 for the event loop has a slightly different
> > implementation from that used in TclBlend with a comment about "reading
> only
> > 1 byte at a time to avoid some race condition".
>
> I'm not sure what would be causing a busy loop. Can you tell what it is
> looping on? The basic procedure should be that one or more threads write
> a byte onto the pipe. The select thread will read one byte per select()
> iteration. The only way it could loop is if some thread was repeatedly
> writing to the pipe or if the select thread failed to consume data from
> the pipe.
After spending some hours in gdb tracing the program, it seems that the problem occurs
in tclUnixChan.c:FileInputProc() line 380: *errorCodePtr = errno;
1 byte is written to a non-blocking Tcl file channel. Then 1 byte is successfully
read from the channel. Then Tcl calls FileInputProc() again to read more. There is
no more data in the channel, so the call at tclUnixChan.c, line 376
bytesRead = read(fsPtr->fd, buf, (size_t) toRead);
returns -1. However, for some reason, the system variable "errno" is always 0, not
EAGAIN as expected by the caller function. This causes the caller function
(tclIO.c:GetInput(), line 4865) to loop forever calling FileInputProc() over and over
again.
I have not determined what caused the problem with "errno". The Tcl library is loaded
into a JVM at this point. So the process is running in multi-threaded mode. The Tcl
library used is non-threaded, version 8.3.1. Can there be something bad about using
"errno" from multiple threads?
Another strange thing if I run the same Java program on a smaller example, then it
seems to work OK. When the error does happen, there are many threads in the process.
-- Jiang Wu
[EMAIL PROTECTED]
----------------------------------------------
[EMAIL PROTECTED] is brought to you by
the Stanford Alumni Association and Critical Path.
----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe: send mail to [EMAIL PROTECTED]
with the word SUBSCRIBE as the subject.
To unsubscribe: send mail to [EMAIL PROTECTED]
with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'.
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com