On Fri, 2012-07-06 at 08:11 +0200, [email protected] wrote:
> Hi
> 
> I need to check (for debugging purposes) if current thread is main
> thread. How can I do that in Vala?
> 
> I know that in GLib exists g_thread_self() and I can  use result of
> that function for that purpose but in Vala's vapi it has strange
> syntax that I cannot truly understand.
> 
> Thank you in advance,
> 
> m.

I know that this is a very old email :)

Just for future reference:

using GLib;

public class ThreadSelf {
        private unowned Thread<void*> main_thread;
        
        public ThreadSelf () {
                main_thread = Thread.self<void*> ();
                unowned Thread<void*> thread = Thread.create<void*> (this.fun, 
false);
                Thread.usleep (100);
        }
        
        public void* fun () {
                stderr.printf("ThreadSelf.fun - running in main thread: %s\n",
Thread.self<void*>() == main_thread ? "yes" : "no");
                return null;
        }
        
        public static void main () {
                var thread = new ThreadSelf();
                thread.fun ();
        }
}

HTH,
Andrea

_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to