After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 746262 - Should be able to stop a GLib.ThreadPool
Should be able to stop a GLib.ThreadPool
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings: GLib
0.27.x
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks: 736773
 
 
Reported: 2015-03-15 22:47 UTC by Michael Catanzaro
Modified: 2015-03-18 15:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add ThreadPool.free (1.07 KB, patch)
2015-03-18 11:07 UTC, Luca Bruno
none Details | Review

Description Michael Catanzaro 2015-03-15 22:47:31 UTC
We have code that uses a GLib.ThreadPool to perform an asynchronous operation (bug #736773), and want to make the operation cancellable using GLib.Cancellable. But once we detect that the Cancellable has been canceled, we have no way to stop the ThreadPool from performing more work! In C this is done using a call like g_thread_pool_free (pool, TRUE, FALSE), which also frees the pool. The destructor is hardcoded in valaccodebasemodule.vala (bug #542725) to always be called as g_thread_pool_free (pool, FALSE, TRUE), which was probably good choice. But drat!

I'm not really sure how to handle this well. I guess a method ThreadPool.stop that invokes g_thread_pool_free with the second parameter FALSE, but that would require a huge warning that such ThreadPools should be nullable and carefully checked to be sure it's not null... probably not the way to go. I imagine this is an issue for other language bindings too, so I checked Python GI, which just exposes free as-is. That's probably the right thing to do: it's obvious enough that programmers should be careful when calling a method named free....
Comment 1 Luca Bruno 2015-03-18 10:55:55 UTC
I think here the easiest way is using a static method wrapper with a pointer to the variable, which calls free() and then nullify the variable.

For vala devs:

The more correct way instead is to add a free() method with [DestroysInstance], however this is a little problematic in the compiler atm, unfortunately. With reference-counted objects, it works fine because a ref is done, but with compact classes the reference must be transferred.
Comment 2 Luca Bruno 2015-03-18 11:07:52 UTC
Created attachment 299698 [details] [review]
add ThreadPool.free

Use like this: ThreadPool.free ((owned) tp, true, false);

Does this solve your problem?
Comment 3 Michael Catanzaro 2015-03-18 15:34:37 UTC
Yes, that patch works for me. Thanks!
Comment 4 Luca Bruno 2015-03-18 15:47:51 UTC
commit 476247f68c6c2fba4043759e9caebc917e49d951
Author: Luca Bruno <lucabru@src.gnome.org>
Date:   Wed Mar 18 12:06:59 2015 +0100

    glib-2.0: provide access to original ThreadPool.free()
    
    Fixes bug 746262

This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.