From: "Jeff Henrikson" To: Subject: Thread wedge in lablgtk Date: Fri, 29 Jun 2001 16:52:08 -0400 Message-ID: <000a01c100dd$5c7db840$0b01a8c0 at mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Importance: Normal Okay, so I am still having trouble with multithreading GTK on Windows 98. (Using the bytecode compiler, but I think native does the same thing.) Basically, I have a test program that makes a window and draws one of two things in it based on a state variable. I set up a thread that infinite loops on: toggle state variable queue redraw request sleep 1 sec. The behavior is that the application wedges sometime after painting itself. It never unsleeps. However, if any window messages happen to get sent (eg, mousemove, keypresses, etc, the thread gets unwedged provided the 1 second time has in fact expired. Ways I have experimented: 1) I put printfs before and after every critical thing to determine that the last code that runs is consistently the last paint handler command. I'll put the code below. 2) I replaced Thread.sleep with a custom C function that called Win32 Sleep(int msecs). Same behavior. My code is a modified version of the test sample drawing.ml. It is below. Many thanks, Jeff Henrikson drawing.ml: open GMain;; open Thread;; open GObj;; open GtkBase;; open Printf;; let window = GWindow.window () let area = GMisc.drawing_area ~packing:window#add () let w = area#misc#realize (); area#misc#window let drawing = new GDraw.drawable w let rec hun = ref 100 let redraw _ = match drawing#size with (w,h) -> drawing#set_foreground `WHITE; drawing#rectangle ~x:0 ~y:0 ~width:w ~height:h ~filled:true(); drawing#set_foreground `BLACK; drawing#polygon ~filled:true [ 10,!hun; 35,35; 100,10; 165,35; 190,100; 165,165; 100,190; 35,165; 10,100 ]; (printf "dequeue size=(%d,%d) " w h; flush stdout; 0 ); false (*external emit_happy : GMisc.drawing_area -> name:string -> unit -> unit = "ml_gtk_signal_emit_none"*) let interactionThread i = while true do hun := - !hun; printf "queue "; flush stdout; GtkBase.Widget.queue_draw (window : GWindow.window :> widget)#as_widget; printf "sleep "; flush stdout; Thread.delay 0.1; (*Sleep.sleep 100;*) (* custom native sleep: same behavior *) printf "unsleep "; flush stdout; done; false let _ = window#connect#destroy ~callback:Main.quit; area#event#connect#expose ~callback:redraw; window#show (); let handle = Thread.create interactionThread 8 in Main.main ()