import vibe.core.core : runWorkerTaskH; __gshared int counter; __gshared TaskMutex mutex; mutex = new TaskMutex; Task[] tasks; foreach (i; 0 .. 100) { tasks ~= runWorkerTaskH(() nothrow { auto l = scopedMutexLock(mutex); counter++; }); } foreach (t; tasks) t.join(); assert(counter == 100);
Performs RAII based locking/unlocking of a mutex.
Note that while TaskMutex can be used with D's built-in synchronized statement, InterruptibleTaskMutex cannot. This function provides a library based alternative that is suitable for use with all mutex types.