Re: libseed-list bug with threads and closures?



Avoid threads is normally the answer ;)

have you had a play with the transfer ownership stuff..

= this is the thread_create_full first argument - it's tranfer none, which in theory
means that the function is available for gc after the method is called.

      <parameters>
        <parameter name="func"
                   transfer-ownership="none"
                   scope="call"
                   closure="1">
          <type name="ThreadFunc" c:type="GThreadFunc"/>
        </parameter>


Regards
Alan

 --- On 02/Aug/2010, Jonatan Liljedahl wrote: 
> Any ideas on this? I'm stuck.. Hoping someone with more insight in 
> closures and gobject-introspection might help.
> 
> /Jonatan
> 
> On 07/28/2010 04:06 PM, Jonatan Liljedahl wrote:
> > This simple code crashes (output and stacktrace at the end of this
> > mail). I don't see why it shouldn't work. GLib.idle_add() is the
> > recommended way to defer stuff from a thread to the mainloop and I've
> > used it several times in C code.
> >
> > Seems to be a problem with closures, threads and the garbage collector?
> >
> > /////////// thread_bugs.js ////////////
> > 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();
> >
> > b.signal.clicked.connect(function() {
> > print("Clicked");
> > 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");
> > GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE,function() {
> > print("In mainloop");
> > b.label = "Bar"+x;
> > return false;
> > });
> > },null,0,true);
> > });
> >
> > Gtk.main();
> > //////////// EOF /////////////
> >
> > Clicked
> >
> > ** (seed:2184): WARNING **: ArgumentError - probably due to incorrect
> > gir file (which may be fixed upstream) argument 2 must not be null for
> > function: thread_create_full
> >
> > [New Thread 0xb57d8b70 (LWP 2188)]
> > Thread start
> > 3.05975143636762e+17
> > Dispatch to mainloop
> > In mainloop
> >
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x00cdbd12 in ?? () from /usr/lib/libwebkit-1.0.so.2
> > (gdb) bt
> > #0 0x00cdbd12 in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #1 0x00cdc8a4 in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #2 0x00cdc905 in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #3 0x00cdd845 in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #4 0x00cde4f0 in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #5 0x00be63b3 in JSGlobalContextRelease () from /usr/lib/libwebkit-1.0.so.2
> > #6 0x00137bb6 in seed_handle_closure (cif=0x81ccc00, result=0xbfffec38,
> > args=0xbfffebd0, userdata=0x81cb7e8) at seed-closure.c:290
> > #7 0x003aa316 in ?? () from /usr/lib/libffi.so.5
> > #8 0x003aa6fa in ?? () from /usr/lib/libffi.so.5
> > #9 0x00301151 in ?? () from /lib/libglib-2.0.so.0
> > #10 0x00303165 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
> > #11 0x00306f88 in ?? () from /lib/libglib-2.0.so.0
> > #12 0x003074c7 in g_main_loop_run () from /lib/libglib-2.0.so.0
> > #13 0x0132c3c9 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
> > #14 0x003aa63f in ffi_call_SYSV () from /usr/lib/libffi.so.5
> > #15 0x003aa46f in ffi_call () from /usr/lib/libffi.so.5
> > #16 0x0039c799 in g_function_info_invoke ()
> > from /usr/lib/libgirepository-1.0.so.0
> > #17 0x0013bb4a in seed_gobject_method_invoked (ctx=0xb636e098,
> > function=0xb5f3be80, this_object=0xb6338ac0, argumentCount=0,
> > arguments=0xbffff0d0, exception=0xbffff11c) at seed-engine.c:656
> > #18 0x00be20be in ?? () from /usr/lib/libwebkit-1.0.so.2
> > ---Type <return> to continue, or q <return> to quit---
> > #19 0x00c28f1a in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #20 0x02614236 in ?? ()
> > #21 0x00c3a7ce in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #22 0x00cf5b66 in ?? () from /usr/lib/libwebkit-1.0.so.2
> > #23 0x00bdc4a9 in JSEvaluateScript () from /usr/lib/libwebkit-1.0.so.2
> > #24 0x0013860c in seed_evaluate (ctx=0xb67a2e24, s=0x80579c0, this=0x0)
> > at seed-api.c:279
> > #25 0x08048f01 in seed_exec (filename=0xbffff64c "thread_bugs.js") at
> > main.c:95
> > #26 0x08049134 in main (argc=2, argv=0xbffff4c4) at main.c:161
> >
> > Running with --seed-debug=all says:
> > ...
> > Clicked
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: func (0) of
> > function thread_create_full, exception is 0xbff862b4
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: data (1) of
> > function thread_create_full, exception is 0xbff862b4
> >
> > ** (seed:2209): WARNING **: ArgumentError - probably due to incorrect
> > gir file (which may be fixed upstream) argument 2 must not be null for
> > function: thread_create_full
> >
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: stack_size
> > (2) of function thread_create_full, exception is 0xbff862b4
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: joinable (3)
> > of function thread_create_full, exception is 0xbff862b4
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: bound (4) of
> > function thread_create_full, exception is 0xbff862b4
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: priority (5)
> > of function thread_create_full, exception is 0xbff862b4
> > ** Message: [INVOCATION] seed-engine.c:655: Invoking method:
> > thread_create_full with 6 'in' arguments and 0 'out' arguments
> > ** Message: [IMPORTER] seed-importer.c:485:
> > seed_gi_importer_get_property with GLib
> > ** Message: [IMPORTER] seed-importer.c:389: Using existing namespace ref
> > (0xb5bc3b40) for GLib
> > ** Message: [IMPORTER] seed-importer.c:498: Result (0xb5bc3b40) from
> > attempting to import GLib: [object Object]
> > ** Message: [INVOCATION] seed-closure.c:63: Invoking closure of type:
> > ThreadFunc
> >
> > Thread start
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9ef4050. with priv->free_pointer = 0 with type: Thread, size: 2863311530
> > 3.05975143636762e+17
> > Dispatch to mainloop
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: priority (0)
> > of function idle_add, exception is 0xb509be3c
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: function (1)
> > of function idle_add, exception is 0xb509be3c
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: data (2) of
> > function idle_add, exception is 0xb509be3c
> > ** Message: [INVOCATION] seed-engine.c:532: Converting arg: notify (3)
> > of function idle_add, exception is 0xb509be3c
> > ** Message: [INVOCATION] seed-engine.c:655: Invoking method: idle_add
> > with 4 'in' arguments and 0 'out' arguments
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd4520. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5180. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd51b0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5400. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5460. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd54c0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd54f0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5520. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5550. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5580. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd55b0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5600. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5630. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5660. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5690. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd56f0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5720. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5780. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd57b0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5800. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5830. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5950. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5980. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd59b0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5a00. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5a30. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5a60. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5a90. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5ac0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5ac0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5af0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5af0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5b20. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5b80. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd5b20. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6400. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6400. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6430. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6430. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6460. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6460. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6490. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6490. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd64c0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd64f0. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > ** Message: [STRUCTS] seed-structs.c:50: Finalizing seed_pointer object
> > 0x9dd6520. with priv->free_pointer = 0 with type: IBaseInfo, size: 0
> > Segmentation fault
> > _______________________________________________
> > libseed-list mailing list
> > libseed-list gnome org
> > http://mail.gnome.org/mailman/listinfo/libseed-list
> 
> _______________________________________________
> libseed-list mailing list
> libseed-list gnome org
> http://mail.gnome.org/mailman/listinfo/libseed-list



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