Am 23.04.2016 um 20:39 schrieb chmike:

As a beginner in D and Vibe programming I have a hard time finding code examples online.

I'm currently trying to find out how to use vibe's fiber friendly mutexes. Is the following code the correct way to use mutexes ? I suppose synchronizing on the object is nos OK because the mutex in the base object is not a fiber friendly mutex.

final class Store {
   auto mtx = new TaskMutex;
   int count = 0;
   // Return the incremented value of count in a string
   string getIncrementedCount()
   {
     synchronize(mtx)
     {
       count += 1;
       return to!string(count);
     }
   }
}

Looks good, although in this specific case you wouldn't really need to
use a TaskMutex (it has some performance overhead). That is only
required if any blocking operations (I/O, receiving messages, sleeping,
yield'ing) take place while the mutex is locked. So if that's not the
case, using the object's own monitor is fine, too.