Advantages of using condition variables over mutex

A condition variable allows a thread to be signaled when something of interest to that thread occurs. By itself, a mutex doesn’t do this. If you just need mutual exclusion, then condition variables don’t do anything for you. However, if you need to know when something happens, then condition variables can help. For example, if … Read more

Is using a Mutex to prevent multiple instances of the same program from running safe?

It is more usual and convenient to use Windows events for this purpose. E.g. static EventWaitHandle s_event ; bool created ; s_event = new EventWaitHandle (false, EventResetMode.ManualReset, “my program#startup”, out created) ; if (created) Launch () ; else Exit () ; When your process exits or terminates, Windows will close the event for you, and … Read more

std::mutex performance compared to win32 CRITICAL_SECTION

Please see my updates at the end of the answer, the situation has dramatically changed since Visual Studio 2015. The original answer is below. I made a very simple test and according to my measurements the std::mutex is around 50-70x slower than CRITICAL_SECTION. std::mutex: 18140574us CRITICAL_SECTION: 296874us Edit: After some more tests it turned out … Read more

WPF Single Instance Best Practices [closed]

There are Several choices, Mutex Process manager Named Semaphore Use a listener socket Mutex Mutex myMutex ; private void Application_Startup(object sender, StartupEventArgs e) { bool aIsNewInstance = false; myMutex = new Mutex(true, “MyWPFApplication”, out aIsNewInstance); if (!aIsNewInstance) { MessageBox.Show(“Already an instance is running…”); App.Current.Shutdown(); } } Process manager private void Application_Startup(object sender, StartupEventArgs e) { … Read more

Are mutex lock functions sufficient without volatile?

Simplest answer is volatile is not needed for multi-threading at all. The long answer is that sequence points like critical sections are platform dependent as is whatever threading solution you’re using so most of your thread safety is also platform dependent. C++0x has a concept of threads and thread safety but the current standard does … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)