Re: libseed-list bug with threads and closures?



On 07/28/2010 04:06 PM, Jonatan Liljedahl wrote:
Seems to be a problem with closures, threads and the garbage collector?

The code below works most of the times (the thread and the idle-source is stored in a global variable). But not every time so I don't know what it proves..

var Gtk = imports.gi.Gtk;
Gtk.init(0,0);

var w = new Gtk.Window({border_width: 20});
var b = new Gtk.Button({label: "Foo"});
w.add(b);
w.show_all();

var thread, idle;

b.signal.clicked.connect(function() {
    print("Clicked");
    thread = GLib.thread_create_full(function() {
        print("Thread start");
        var i=0;
        var x=1.3;
        for(i=0;i<9999999;i++) {
            x *= 1.000004;
        };
        print(x);
        print("Dispatch to mainloop");
        idle = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE,function() {
            print("In mainloop");
            b.label = "Bar"+x;
            return false;
        });
    },null,0,true);
});

Gtk.main();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]