On Mon, 15 May 2000, Scott Redman wrote:

> I was reading Jiang Wu's paper on using Java and Tcl.  I have
> a question for everyone:

Jiang's Wrapper Layer is a neat idea, but there are a couple of
problems with it. You can't really wrap individual Interp
calls because often you need to call other methods like
ReflectObject.get() or TclInteger.get(). Also, looking at
code like:

TclObject one = WrappedInterp.getVar("one");
TclObject two = WrappedInterp.getVar("two");

A user might expect that the value of two would be queried
right after the value for one, but that may not be true.
If getting the value of one calls some trace proc, then
it might do a bunch of stuff and put events into the event
loop before the wrapped call to get "Two" happens. What
is really needed is to wrap a series of generic API
calls in a block of code like so:

synchronized (SOMETHING) {
  TclObject one = interp.getVar("one");
  TclObject two = interp.getVar("two");
}

I suggested that using an inner class would be the way
to go, but that approach is still a little bit complex.
(see the current src/jacl/tcl/lang/Shell.java for an example).

> I want to create a single Tcl interp and access it from only
> one Java thread, as per Jiang's Wrapper Layer (sending events
> to the one "owner" thread).  That Tcl interp will spawn
> threads in Tcl and have those interps do all of the work.
> As long as I'm using thread-enabled Tcl 8.3.1, this should
> all work fine.

Do you mean using java::* commands to access the Java objects
or just getting a Java ref to the objects in your code and
then passing those around? If you are just passing Java
object handles around in your native Java code, that would
work. If you intend to use java::* commands, it should work
but keep in mind that the java::* commands will be processed
on at a time because there is a "big global lock" that must
be grabbed before the JVM can be accessed (see JAVA_LOCK).

> Here is the problem.  I want to access Java objects through
> TclBlend from each of the Tcl threads.  It sounds like this
> will not work, but can someone explain to me the technical
> reason why?

You should be able to use multiple interps, they just need to
proccess events one at a time. I have not tested it, so
it is very likely that it is broken:)

>  I believe this is because TclBlend doesn't
> allow Tcl interps in more than one thread (from Jiang's
> paper), or is this only when Tcl has not been built with
> threads?

Bring this up during the SVTUG tommorow night.

> I might be able to have someone (or myself) do some of the 
> advance work in making this happen for tcljava 1.3.  I'd
> like to make sure that the discussions happen earlier
> rather than later.
> 
> -- Scott

Later
Mo DeJong

----------------------------------------------------------------
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