File: runthread.ml

package info (click to toggle)
lablgtk3 3.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,796 kB
  • sloc: ml: 40,890; ansic: 22,312; makefile: 133; sh: 17
file content (30 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(**************************************************************************)
(*    Lablgtk - Examples                                                  *)
(*                                                                        *)
(*    This code is in the public domain.                                  *)
(*    You may freely copy parts of it in your application.                *)
(*                                                                        *)
(**************************************************************************)
let start = GButton.button ~label:"Start" ~packing:vbox#pack ()
let stop = GButton.button ~label:"Stop" ~packing:vbox#pack ()
let text = GEdit.entry ~packing:vbox#pack ()

let cont = ref true
let n = ref 0

let body () =
  prerr_endline "started";
  while !cont do
    incr n;
    async text#set_text (string_of_int !n);
    Thread.delay 1.
  done

let () =
  GMain.init ();
  start#connect#clicked
    (fun () -> cont:= true; ignore (Thread.create body ()));
  stop#connect#clicked (fun () -> cont := false);
  w#connect#destroy GMain.quit;
  w#show ();
  GMain.main ()