On Mon, 1 May 2000, Jeff Sturm wrote:

> Mo DeJong wrote:
> > The term "thread safe" is very misleading. Jacl interps are safe
> > if you use them properly. The problem is that the documentaiton
> > about how to use them properly is a little thin.

There is no "automatic thread safety" in TclJava. In fact, Java itself
never got "automatic thread safety" completely right. The AWT was
a great example of how not to write a GUI (with lots of "automatic"
thread locking).
 
> You could say the same about most Java code.  But I agree the term
> "thread safe" is not very precise.  I was referring to automatic thread
> safety... which, depending on the project, there may be good reasons to
> shun for performance reasons (Swing is a good example).

It does. The docs say that ALL methods that interact with an interp
instance and thread unsafe. For this reason, all interp interaction
needs to be done from the Tcl event queue thread. Here is a quick
example that call the "unsafe" eval() method using the Notifier
to queue up a "thread safe" event.

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 seomthing to handle the error
        }
        return 1;
      }
    };

    interp.getNotifier().queueEvent(event, TCL.QUEUE_TAIL);

  }

}

Note how the setXto1() method is called from the interp event
queue thread (the paper does a better job of explaining this).

> The API docs should at least specify which calls are safe to use
> concurrently and which are not.
> 
> > A new paper on
> > the subject of multi-threaded interaction with a TclJava interp
> > is being authored by Jiang Wu <[EMAIL PROTECTED]>. I am sure
> > he will publish the URL on this list when he thinks it is ready
> > (If you want to help out, I am sure Jiang could always use another
> > pair of eyes to help review the paper).

Cool, shoot Jiang an email, I am sure he would welcome the help.

> Good.  I'd welcome a chance to review it.
> 
> -- 
> Jeff Sturm
> [EMAIL PROTECTED]
> 

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

Reply via email to