On Mon, 2011-06-20 at 17:37 -0700, Jim Nelson wrote: > With async, the delegate *is* copied, you just don't see it in the > Vala code. With an async method, when the thread of execution yields, > the state of the function at that point is stored (copied or ref'd) in > a context structure. When the thread of execution resumes later, the > state is pulled back out and the function resumes.
Has that any bearing on the bug I mentioned in my earlier email? > I also get segmentation fault trying to pass > a closure accessing local variables. The closure > works if it doesn't access local vars. > > e.g., > var f = etc; > async_func ( () => { fn (f);} ); > > will crash trying to access f. Apparently > the closure isn't properly constructed. In the following example, the closure bug doesn't lead to a crash. But it is apparent in the output. Expected output: hello hello hello bye Actual output: hello hello (null) bye The code: public class Foo : Object { public delegate void DelegateType (); async void f3 (DelegateType d) { d (); } async void f2 (DelegateType d) { d (); yield f3 (d); d (); // <----- x local to f1 has gone stdout.printf ("bye\n"); } void f1 () { var x = "hello"; f2 (() => {stdout.printf ("%s\n", x);}); } public static int main(string[] args) { var foo = new Foo (); foo.f1 (); new MainLoop (null, false).run (); return 0; } } hand Nor Jaidi Tuah _______________________________________________ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list