mutex

How to implement an MVC 4 web App server side mutex

给你一囗甜甜゛ 提交于 2019-12-08 18:39:59
问题 I'm no MVC expert, but I'm fairly sure this is implementable; however, I don't know how to do it in MVC 4. For testing, I'm using the default web app given when you create a site using VS 2012. Consider, for simplicity, that HomeController.Index() is hit at exactly the same time by multiple users (for example 3). I want to execute a method that is mutexed so as only one will execute at a time; hence forcing them serially. I don't care what order. I know of the warnings about blocking a page

How can you implement a condition variable using semaphores?

雨燕双飞 提交于 2019-12-08 17:37:57
问题 A while back I was thinking about how to implement various synchronization primitives in terms of one another. For example, in pthreads you get mutexes and condition variables, and from these can build semaphores. In the Windows API (or at least, older versions of the Windows API) there are mutexes and semaphores, but no condition variables. I think that it should be possible to build condition variables out of mutexes and semaphores, but for the life of me I just can't think of a way to do

Why ApplicationException is thrown?

Deadly 提交于 2019-12-08 16:45:36
I am just experimenting on Mutex and wrote the following code. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace Mutex_WaitOnewithTimeouts { class Program { private static Mutex mut = new Mutex(); private static int numOfThreads = 5; private static int numOfIterations = 3; private static Random rand = new Random(); static void Main(string[] args) { Thread[] threads = new Thread[5]; for (int num = 0; num < numOfThreads; num++) { threads[num] = new Thread(new ThreadStart(MyThreadProc)); threads[num].Name = String.Format(

C/C++ arrays with threads - do I need to use mutexes or locks?

拈花ヽ惹草 提交于 2019-12-08 15:55:31
问题 I am new to using threads and have read a lot about how data is shared and protecting data. But I have also not really got a good grasp of when I need to use mutexes and locks to protect data. Below is a description of the problem I will be working on. The important thing to note is that it will be time critical so I need to reduce overheads as much as possible. I have two fixed size double arrays. The first array will provide data for subsequent calculations. Threads will read values from it

Is this the proper use of a mutex?

陌路散爱 提交于 2019-12-08 15:41:38
问题 I have a situation where I might have multiple instances of a program running at once, and it's important that just one specific function not be executing in more than one of these instances at once. Is this the proper way to use a mutex to prevent this from happening? lock (this.GetType()) { _log.Info("Doing Sync"); DoSync(); _log.Info("Sync Completed"); } 回答1: You said multiple instances of one application, so we're talking about two program.exe's running, right? The lock statement won't

Creating a Mutex throws a DirectoryNotFoundException

泪湿孤枕 提交于 2019-12-08 14:46:55
问题 I'm trying to create a named mutex, but when I call the constructor I get a DirectoryNotFoundException ! Why is a mutex trying to access the filesystem, and how do I know what is a valid path? Is there any particular directory the mutex should be placed in, and how does that correspond to the name? EDIT: I'm using the Mutex(bool, string) overload, and the exception is: System.IO.DirectoryNotFoundException: Could not find a part of the path '<mutex name>'. at System.IO.__Error.WinIOError(Int32

Semaphore Vs Condition Variables in multithreading?

守給你的承諾、 提交于 2019-12-08 13:39:35
问题 Problem : I have to increment x1 and x2 variable which should be done by separate threads and next increment of both variables should not be called until previous increment of both variable is not completed. Problem: x1 = 0; x2 = 0; x1++; and x2++; should run parallel on different threads and wait for printing. should print: x1 = 1 and x2 = 1 x1++; and x2++; should run parallel on different threads and wait for printing. should print: x1 = 2 and x2 = 2 x1++; and x2++; should run parallel on

Correctly using mutex in OpenCL-OpenCV-Realtime-Threads?

房东的猫 提交于 2019-12-08 12:18:27
问题 Im trying to get a stereo-videostream in realtime via usb-webcams in a GPU-Thread (way faster than to get and process the images via cpu), processing said stream in a second thread to get the faces and control the threads via keyboard in the main-function (will be implemented later). At the moment the code runs properly (shows both Links/Rechts and draws a rectangle around my face) for ~30s and then crashes because of an "...unhandled exception (opencv_core249d.dll)". Ive tried using mutex

Mutex that works across std implementations

为君一笑 提交于 2019-12-08 11:14:51
问题 Related to this question, I need a mutex that works across std implementations, or a way to atomically write and read a pointer. One thread is spawned by code compiled with mingw-w64 and the other one is Visual Studio 2019 code in a static/dynamic library. 回答1: Export from your main executable (mingw-w64) to your DLL (VC++) - compiled with separate compilers - a synchronization/mutex "handle" (an opaque pointer, typically, though it can be an index into something too) and a pair of C-style

How do i make the mutex not be recusive?

一世执手 提交于 2019-12-08 11:06:30
问题 I ran the code below expecting flow to be locked on the 2nd time i lock a mutex. After running it twice i realize it can lock many times (assuming in the same thread) without stopping. How do i change this behavior? using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace Test { class Program { static volatile Mutex mut1 = new Mutex(); static volatile Mutex mut2 = new Mutex(); static void Main(string[] args) { mut1.WaitOne(); Console.WriteLine("1W")