01: package tests;
02:
03: import tcl.lang.*;
04:
05: /*
06: This class is designed to test a deadlock condition in the
07: tcl.lang.Notifier class. There was a problem with deadlocking
08: if a vwait was entered through the Notifier loop, it would
09: keep other events from being queued up. This class is used
10: in tcljava/TclEvent.test in test TclEvent-1.4.
11: */
12:
13: public class AppendEventQueueThread extends Thread {
14: private Interp interpInOtherThread;
15: public final int expectedNumQueued = 5;
16: public int numQueued = 0;
17: public int numProcessed = 0;
18:
19: private static final boolean debug = false;
20:
21: public AppendEventQueueThread(Interp i) {
22: interpInOtherThread = i;
23: }
24:
25: public void run() {
26: if (debug) {
27: System.out.println("running AppendEventQueueThread");
28: }
29:
30: for (int i = 0; i < expectedNumQueued; i++) {
31: try {
32: Thread.sleep(1000);
33: } catch (InterruptedException e) {
34: }
35:
36: TclEvent event = new TclEvent() {
37: public int processEvent(int flags) {
38: numProcessed++;
39: if (debug) {
40: System.out.println("processed event "
41: + numProcessed);
42: }
43: return 1;
44: }
45: };
46:
47: // Add the event to the thread safe event queue
48: interpInOtherThread.getNotifier().queueEvent(event,
49: TCL.QUEUE_TAIL);
50: numQueued++;
51: if (debug) {
52: System.out.println("queued event " + numQueued);
53: }
54: }
55:
56: if (debug) {
57: System.out.println("done running AppendEventQueueThread");
58: }
59: }
60:
61: public static void queueVwaitEvent(final Interp interp) {
62: TclEvent event = new TclEvent() {
63: public int processEvent(int flags) {
64: try {
65: interp.eval("after 10000 {set wait 1}", 0);
66: interp.eval("vwait wait", 0);
67: } catch (TclException ex) {
68: ex.printStackTrace();
69: }
70: return 1;
71: }
72: };
73:
74: // Add the event to the thread safe event queue
75: interp.getNotifier().queueEvent(event, TCL.QUEUE_TAIL);
76: if (debug) {
77: System.out.println("queued vwait event");
78: }
79: }
80: }
|