Re: [Vala] Thread Support
- From: Jim Nelson <jim yorba org>
- To: Daniel Espinosa <esodan gmail com>
- Cc: Vala-list <vala-list gnome org>
- Subject: Re: [Vala] Thread Support
- Date: Wed, 13 Aug 2014 12:02:54 -0700
On Wed, Aug 13, 2014 at 10:55 AM, Daniel Espinosa <esodan gmail com>
wrote:
I have an async function called directly in my code. When compiles I
get
this:
XXXXXXX: warning: implicit .begin is deprecated
That means you called the async method with neither a yield keyword nor
with the begin modifier. You need to do either this:
yield read_async();
or this:
read_async.begin();
Vala used to support:
read_async()
as being equivalent to using .begin(), but that form was deprecated,
hence the message you're seeing.
Thread<void> th = new Thread<void>.try ("loading scl", () => {
async_function (); /*Asinc function */
return null;
});
th.join ();
Error message is:
XXXXX: error: The name `try' does not exist in the context of
`GLib.Thread'
I've checked glib-2.0.vapi, for both vala-0.20 and 0.22, that
function is
present just for GLIB_2_32, checking my installed version I have a
2.40 on
a GNOME Ubuntu 14.04 box.
Add this flag to valac:
--target-glib=2.40
or:
--target-glib=2.32
Be aware by doing this you're making your app incompatible with earlier
versions of glib.
Regarding your code itself, there's a few more problems. First, you
can't use <void> as a type parameter, you must give an actual type that
represents storage. "void *" is probably the best way to go if you
truly have nothing to pass to your threads.
Second, you're calling an async method within the background thread.
There's nothing technically wrong with this, but I suspect that's not
what you really want. The usual pattern of use is to call the async
method from your main ("foreground") thread. The async call might use
background threads as an implementation strategy (to do the work
without blocking the foreground thread).
-- Jim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]