Threading in Vala

Locks

Lock can be used like in C#. The main difference is, that you can only lock members of your class.

/* Vala Lock Example */
using GLib;

public class Sample : GLib.Object {

        private int critical_data;

        public void inc () {
                
                lock (critical_data) {
                        critical_data++;
                }
        }

        static void main (string[] args) {
                
                var sample = new Sample ();
                sample.inc ();
        }
}

Compile

$ valac lock.vala
$ gcc $(pkg-config --cflags --libs gobject-2.0 gthread-2.0) -o lock lock.c

Projects/Vala/Threading (last edited 2013-11-22 16:48:27 by WilliamJonMcCann)