Hi all.

I seem to have run into a really big problem with the java::bind
command that I need some help with. The problem only seems to
show up in Tcl Blend, and I have only tested it on my RedHat 5.2
Linux box thus far. Could people on the list try out this example
and post the results they get? The problem seems to be that when
another Java thread invokes a callback created with the java::bind
command, the Tcl callback never gets invoked and the other thread
gets deadlocked. This same code works just fine in Jacl.

Mo Dejong
Red Hat Inc.



// Start of file Bind.java

// This class implements a bindable object that will
// generate an event to a tcljava binding (java::bind)

import java.util.EventObject;
import java.util.EventListener;

public class Bind implements Runnable {
    ActionListener actionListener = null;
    Thread t = null;
    boolean started;
    boolean stopped;
    int tnum = 0;

    final boolean debug = true;

    public void addActionListener(ActionListener l) {
        actionListener = l;
    }

    public void removeActionListener(ActionListener l) {
        actionListener = null;
    }

    public void doLater() {
        // Create new thread that will invoke the call to
        // actionListener.actionPerformed(ActionEvent)
        // in another thread at a later time
        
        started = false;
        stopped = false;

        tnum++;
        t = new Thread(this);
        t.setDaemon(true);
        t.setName("Bind delay thread " + tnum);
        t.start();

        if (debug) {
            System.err.println("Waiting to invoke action");
        }
    }

    public void run() {
        started = true;

        // Go to sleep for some time
        try {
        Thread.sleep(3000);
        }
        catch (InterruptedException ie) {}

        if (debug) {
            System.err.println("Now to invoke action");
        }

        // Now invoke the callback (from a different thread)
        actionListener.actionPerformed(new ActionEvent(this));

        stopped = true;
        t = null;
    }

    public boolean wasStarted() {
        return started;
    }

    public boolean wasStopped() {
        return stopped;
    }
}


interface ActionListener extends EventListener {
    public void actionPerformed(ActionEvent e);
}

class ActionEvent extends EventObject {
    ActionEvent(Object source) {
        super(source);
    }
}

// End of file Bind.java




# Tcl code from this bind class
# Be sure to run "javac Bind.java" first


package require java
set env(TCL_CLASSPATH) .

set b [java::new Bind]

set action 0

java::bind $b actionPerformed {
    set action 1
    puts "Hi there"
    #error NO
}

$b doLater


# Wait a little while and see what happened
after 4000 {

if {[$b wasStarted]} {
  puts "Thread Was Started"
}

if {! [$b wasStopped]} {
  puts "Thread Is Deadlocked"
}

if {! $action} {
  puts "No Action Taken"
}

}








Results on Linux:

Jacl under JDK 1.1 from Blackdown:
Works

Tcl Blend under JDK 1.1 from Blackdown:
Hangs, call to Tcl event never made

Same seems to apply for JDK 1.2.




Here is the thread dump from Tcl Blend when the Java thread
is blocked.


Full thread dump:
    "Bind delay thread" (TID:0x405ba390, sys_thread_t:0x807b178, state:CW, thread_t: 
t@4100, sp:0xbf3ff840 threadID:0xef1, stack_base:0xbf3ffd68, stack_size:0x200000) 
prio=5
        tcl.lang.TclEvent.sync(TclEvent.java:126)
        tcl.lang.EventAdaptor._processEvent(EventAdaptor.java:334)
        tcl.lang.Adaptor0.actionPerformed(Unknown Source)
        Bind.run(Bind.java:91)
        java.lang.Thread.run(Thread.java)
    "SIGQUIT handler" (TID:0x405b32a0, sys_thread_t:0x80cdc80, state:R, thread_t: 
t@3075, sp:0xbf5ff40c threadID:0xef0, stack_base:0xbf5ffd68, stack_size:0x200000) 
prio=0 *current thread*
    "Finalizer thread" (TID:0x405b3088, sys_thread_t:0x80cdb60, state:CW, thread_t: 
t@2050, sp:0xbf7ff984 threadID:0xeef, stack_base:0xbf7ffd68, stack_size:0x200000) 
prio=1
    "main" (TID:0x405b30b0, sys_thread_t:0x80cd2d8, state:R, thread_t: t@1024, 
sp:0xbfffef30 threadID:0xeec, stack_base:0x0, stack_size:0x200000) prio=5
Monitor Cache Dump:
    tcl.lang.BeanEvent@1079747800/1080198008: <unowned>
        Waiting to be notified:
            "Bind delay thread" (0x807b178)
    java.lang.Class@1079734352/1080109664: owner "main" (0x80cd2d8, 1 entry)




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