On 7 Aug 2000, Jiang Wu wrote:
> On Mon, 07 August 2000, Mo DeJong wrote:
> > Did a vwait in the callback that was added to the queue
> > in Java (see source code). Then did a normal vwait on the
> > command line.
>
> I am going to try your example tonight. Is this what you mean by doing a normal
>vwait? Can you send me the exact commands used to produce the problem?
>
> % source <... the Tcl script part of your source code ...>
> % set x 1
> % after 20000 {set x 2}
> % vwait x
>
> -- Jiang Wu
> [EMAIL PROTECTED]
Here is the Tcl code.
package require java
set AQT [java::new AppendEventQueueThread [java::getinterp]]
$AQT start
set orig_numQueued [java::field $AQT numQueued]
java::call AppendEventQueueThread queueVwaitEvent [java::getinterp]
set numQueued [java::field $AQT numQueued]
set numProcessed [java::field $AQT numProcessed]
# Kill this other thread.
java::field $AQT killed 1
puts "orig_numQueued = $orig_numQueued"
puts "numQueued = $numQueued"
puts "numProcessed = $numProcessed"
Here is the Java code:
import tcl.lang.*;
public class AppendEventQueueThread extends Thread {
private Interp interpInOtherThread;
public int numQueued = 0;
public int numProcessed = 0;
public boolean killed = false;
private final boolean debug = true;
public AppendEventQueueThread(Interp i) {
interpInOtherThread = i;
}
public void run() {
if (debug) {
System.out.println("running AppendEventQueueThread");
}
while (! killed) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
TclEvent event = new TclEvent() {
public int processEvent (int flags) {
numProcessed++;
return 1;
}
};
// Add the event to the thread safe event queue
interpInOtherThread.getNotifier().queueEvent(event, TCL.QUEUE_TAIL);
numQueued++;
}
if (debug) {
System.out.println("done running AppendEventQueueThread");
}
}
public static void queueVwaitEvent(final Interp interp) {
TclEvent event = new TclEvent() {
public int processEvent (int flags) {
try {
interp.eval("after 10000 {set wait 1}", 0);
interp.eval("vwait wait", 0);
} catch (TclException ex) {
ex.printStackTrace();
}
return 1;
}
};
// Add the event to the thread safe event queue
interp.getNotifier().queueEvent(event, TCL.QUEUE_TAIL);
}
}
Mo DeJong
Red Hat Inc
----------------------------------------------------------------
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