mutex

maximum number of mutexes per process/thread in windows

跟風遠走 提交于 2019-12-19 04:25:13
问题 Is there a limit in the maximum number of mutexes per process/thread in a Asp.net application? Just in case the target operating systems are: Windows XP Pro, server 2003/2008 and Windows 7 in the near future. Usually the website is deployed in an App Pool. 回答1: I'm going to go out on a limb here and venture the possibility that you're probably (not necessarily) doing something wrong. Raymond Chen said it best but, if you're worried about the maximum number of mutexes, you're probably

Boost named_mutex and remove() command

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 00:57:38
问题 I have a class which can be created by multiple threads. But at one function the code needs to be protected, so I decided to use the boost interprocess mutex. Every class creates or opens the same Mutex in it's constructor: MyClass::MyClass() { boost::interprocess::named_mutex m_Lock( boost::interprocess::open_or_create, "myLock" ); } So now there comes the point where the critical code part is called: int MyClass::MyFunction() { boost::interprocess::scoped_lock<boost::interprocess::named

Is std::mutex sequentially consistent?

十年热恋 提交于 2019-12-18 20:04:51
问题 Say, I have two threads A and B writing to a global Boolean variables fA and fB respectively which are initially set to false and are protected by std::mutex objects mA and mB respectively: // Thread A mA.lock(); assert( fA == false ); fA = true; mA.unlock(); // Thread B mB.lock() assert( fB == false ); fB = true; mB.unlock() Is it possible to observe the modifications on fA and fB in different orders in different threads C and D ? In other words, can the following program #include <atomic>

How to signal a ScheduledTask from a foreground app on Windows Phone?

六眼飞鱼酱① 提交于 2019-12-18 16:58:32
问题 I'm creating an app that has a foreground app (of course) and both a PeriodicTask and a ResourceIntensiveTask. I need a way to shutdown the scheduled tasks if the user launches the app itself while they are running. I don't see any way of doing this with system-wide Mutexes. Ideally when the background tasks started, a thread would be spun off that listens for a signal from the foreground app, and if it receives this signal it can shutdown the background task cleanly. Other than polling (say

How to signal a ScheduledTask from a foreground app on Windows Phone?

假装没事ソ 提交于 2019-12-18 16:58:25
问题 I'm creating an app that has a foreground app (of course) and both a PeriodicTask and a ResourceIntensiveTask. I need a way to shutdown the scheduled tasks if the user launches the app itself while they are running. I don't see any way of doing this with system-wide Mutexes. Ideally when the background tasks started, a thread would be spun off that listens for a signal from the foreground app, and if it receives this signal it can shutdown the background task cleanly. Other than polling (say

Windows Event implementation in Linux using conditional variables?

懵懂的女人 提交于 2019-12-18 13:28:50
问题 I am trying to implement very simple Windows events in Linux. Only for my scenario - 3 threads, 1 main and 2 secondary. Each of secondary threads raise 1 event by SetEvent and main thread wait it. Example: int main() { void* Events[2]; Events[0] = CreateEvent(); Events[1] = CreateEvent(); pthread_start(Thread, Events[0]); pthread_start(Thread, Events[1]); WaitForMultipleObjects(2, Events, 30000) // 30 seconds timeout return 0; } int* thread(void* Event) { // Do something SetEvent(Event); //

UnauthorizedAccessException when trying to open a mutex

旧城冷巷雨未停 提交于 2019-12-18 12:27:22
问题 I'm getting this exception when trying to open a mutex (it happens only sometimes; the most of calls is successful): System.UnauthorizedAccessException: Access to the path 'Global\4c7cddf7-e729-43b6-a75c-43f54a0ac6ac' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.Threading.Mutex.OpenExisting(String name, MutexRights rights) The code I'm using to work with mutex: public class MutexLocker : IDisposable { public MutexLocker(string id) { var

If you unlock an already unlocked mutex, is the behavior undefined?

落花浮王杯 提交于 2019-12-18 12:08:25
问题 If you unlock an already unlocked mutex, is the behavior unsafe, safe, or undefined? The purpose of the question is related to the following code, where I don't know if it would be better to unlock the mutexes within the if block, or just outside the if block. // This chunk of code makes dual locking semi-autonomous. int c_lckd = 0, q_lckd = 0; if (pthread_mutex_trylock(&crunch_mutex) == 0) c_lckd = 1; if (pthread_mutex_trylock(&queue_mutex) == 0) q_lckd = 1; if (q_lckd && !c_lckd) { QUEUE

Mutual exclusion and semaphores

爱⌒轻易说出口 提交于 2019-12-18 12:01:05
问题 I am writing a program (for homework) that simulates a unisex bathroom. Only 4 people are allowed at a time and men and woman cannot enter if the other sex is already using the bathroom. My problem is with allowing a max of 4 people in the bathroom. As you can see from the output, only 1 person is getting into the restroom at a time. Here is my code: const int Delayx = 60; int i; int restroom = 0; int Menwaiting = 0; int Womenwaiting = 0; semaphore max_capacity; semaphore woman; semaphore man

Pthread mutex assertion error

南楼画角 提交于 2019-12-18 10:54:43
问题 I'm encountering the following error at unpredictable times in a linux-based (arm) communications application: pthread_mutex_lock.c:82: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed. Google turns up a lot of references to that error, but little information that seems relevant to my situation. I was wondering if anyone can give me some ideas about how to troubleshoot this error. Does anyone know of a common cause for this assertion? Thanks in advance. 回答1: Rock solid for