Hmm.  There is got to be a problem somewhere.  In TclBlend, the native
implementation of Interp.commandComplete() contains:

    JAVA_LOCK();
    cmd = (*env)->GetStringUTFChars(env, cmdStr, NULL);
    result = (Tcl_CommandComplete((/*UNCONST*/ char*) cmd)
        ? JNI_TRUE : JNI_FALSE);
    (*env)->ReleaseStringUTFChars(env, cmdStr, cmd);
    JAVA_UNLOCK();

    return result;

The calls to JAVA_LOCK() will block if this the method is called from any
Java thread other than the event loop thread.  The event loop thread
typically will be in  
Notifier.doOneEvent().  The implementation for that in TclBlend is:

    JAVA_LOCK();
    result = Tcl_DoOneEvent(flags);
    JAVA_UNLOCK();
    return result;

The senario is that the event loop thread is waiting on
Tcl_DoOneEvent(flags) while holding the JAVA_LOCK().  The other thread, e.g.
the console thread, tries to call Interp.commandComplete(), which will also
block on trying to acquire the JAVA_LOCK().  As a result, the shell is
stuck.

If Tcl_CommandComplete(...) is thread safe, then we don't need to use
JAVA_LOCK() in the TclBlend code.  This makes it possible for the console
thread to call Interp.completeCommand() without blocking.  Otherwise, in
TclBlend, the calls to Tcl_CommandComplete will need to be in a TclEvent.  

What do you think?  Is Tcl_CommandComplete() thread safe?  I couldn't find
anything indicating one way or the other.

-- Jiang Wu
   [EMAIL PROTECTED]

-----Original Message-----
From: Mo DeJong [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 16, 2000 1:37 PM
To: Jiang Wu
Cc: [EMAIL PROTECTED]
Subject: RE: [Tcl Java] RE: [Tcl Java] RE: [Tcl Java] tclBlend:
pyramidpkg possible path problem ?

It does? How? Perhaps I did not pick up on that in your last email.
I do not think the call to Interp.commandComplete() is wrong. It is
a static method, so it should be thread safe because it does not
touch any interp instance.

> I was just thrown off course because the implementation of the Jacl
> shell violated the rule on the usage of tcl.lang.Interp.  I was not sure
if
> Jacl did that by design.

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