Consider this simple vala code, which uses some threads with return
value... Since int[] can't be a generics, I need to use an int pointer
for using an integer array as retourn value...
It works as expected, but... If you look at the generated C code, the
pointer returned by g_thread_join (t) is never free'd.
The same happens using strings, but not with more complex object (like
GLib.Array, for example)... Is this a bug?
Why is this happening?
-------
int main(string[] args) {
const int nthreads = 5;
List<unowned Thread<int*>> threads = new List<unowned Thread<int*>>();
for (int i = 0; i < nthreads; ++i) {
try {
unowned Thread<int*> th =
Thread.create<int*>(thread_run, true);
threads.append(th);
} catch (ThreadError e) {}
}
int thi = 0;
foreach (var t in threads) {
int *ret = t.join();
print(@"[$(thi++)] $(ret[0]) - $(ret[1]) - $(ret[2])\n");
}
}
int* thread_run() {
int a = (int) GLib.Random.next_int();
int b = (int) GLib.Random.next_int();
int c = (int) GLib.Random.next_int();
return new int[] {a, b, c};
}
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list