Am 09.01.2014 09:25, schrieb Stanislav:

Hello.
Another question about vibed.

I want to cache some info about authorized users (with singleton). Should i declare that is synchronized functions in singleton? Or vibed make this function blocking?

 struct User {}

 class MySingleton
 {
 public:
   static MySingleton get()
   {
    synchronized
    {
      if (instance_ is null)
      {
        instance_ = new MySingleton;
      }
    }
    return instance_;
   }
   synchronized User getUser() {...}
   synchronized void setUser( User add ) {...}
 private:
   this() {}
   MySingleton instance_;
 }

PS Sorry for bad english.

As long as no I/O, wait or yield operations, are used inside the class
and MySingleton isn't shared between threads (e.g. because
HTTPServerOption.distribute has been enabled), no explicit
synchronization is needed.

Otherwise, you should create a new TaskMutex in MySingleton's
constructor like this: new TaskMutex(this) - this will assign the
mutex as the singleton's monitor. Using the default Mutex on the other
hand can lead to bad performance or deadlocks because it blocks the
thread and thus the event loop.