There has been a lot of interest in thread safety lately, so I
thought I would post a short little example that uses an
innerclass to safely add an event to the event queue.
import tcl.lang.*;
public class EventExample {
// Interact with the Tcl interp (must be called from event loop thread)
void setXto1 (Interp interp)
throws TclException
{
interp.eval("set x 1");
}
// This method can be safely called from any thread
public void SAFE_setXto1(final Interp interp) {
TclEvent event = new TclEvent() {
public int processEvent (int flags) {
try {
setXto1(interp);
} catch (TclException ex) {
// Do something to handle the error
}
return 1;
}
};
interp.getNotifier().queueEvent(event, TCL.QUEUE_TAIL);
//event.sync(); // sync will block the calling thread
// until the event has been processed
}
}
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/[email protected]