mutex

Pthread mutex assertion error

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 ...

Problem with Process.Start() method.

I have a child.exe which takes command line arguments. I need to start that child.exe from another parent.exe application and need to pass different command line arguments to that child.exe. I tried with the following code. Process process = new Process(); process.StartInfo.FileName = @"R:\bin\child.exe"; process.StartIn...

Following code errors out at the line commented with "---errors is here---". What is wrong?

using System; using System.Threading; public class MutexSample { static Mutex gM1; static Mutex gM2; const int ITERS = 100; static AutoResetEvent Event1 = new AutoResetEvent(false); static AutoResetEvent Event2 = new AutoResetEvent(false); static AutoResetEvent Event3 = new AutoResetEvent(false); static AutoR...

Does a lock on a mutex also apply to called functions?

If a mutex is defined within a function, does its lock apply to functions called from that function? ie void f () { Mutex mutex; g(); } Does the lock still apply to any data modifications in g()? Also, am I right to say that a lock defined in a class method will only apply to specific instances of that class? Meaning: ...

Switch Focus between Cmd windows, Force focus (keep 1 instant of program running)

hello, i am creating a simple windows cmd program, and i am trying to make sure it only runs once (if u double click the exe file, only one instance will show.. so in my code.. i added a named mutex(the name is a GUID) .. if a 2nd instance of the program was started, it would show the message telling you, that you already got an instanc...

Guaranteed yielding with pthread_cond_wait and pthread_cond_signal

Assuming I have a C program with 3 POSIX threads, sharing a global variable, mutex, and condition variable, two of which are executing the following psuedocode: ...process data... pthread_mutex_lock( &mutex ); variable = data_ptr; pthread_cond_signal( &cond ); pthread_mutex_unlock( &mutex ); And the third running: while(1) { whil...

N processes and M types of processes - enter and exit cs

i was asked to write: enter function and exit function for the following case: there are N processes and M types of processes (N>>M) tere is a critical section in which all processes with the same type can enter. for example: if type A is in cs, type B cannot enter cs. but all processes with type A can enter. i can use only mutex and "...

How to detect which mutex gives largest amount of time to the OS?

How to measure amount of time given by a mutex to the OS? The main goal is to detect a mutex, that blocks threads for largest amount of time. PS: I tried oprofile. It reports 30% of time spent inside vmlinux/.poll_idle. This is unexpected, because the app is designed to take 100% of its core. Therefore, I'm suspecting, that the time is ...

Why is Boost scoped_lock not unlocking the mutex?

I've been using boost::mutex::scoped_lock in this manner: void ClassName::FunctionName() { { boost::mutex::scoped_lock scopedLock(mutex_); //do stuff waitBoolean=true; } while(waitBoolean == true ){ sleep(1); } //get on with the thread's activities } Basically it sets waitBoolean, and the ...

Overhead of pthread mutexes?

I'm trying to make a C++ API (for Linux and Solaris) thread-safe, so that its functions can be called from different threads without breaking internal data structures. In my current approach I'm using pthread mutexes to protect all accesses to member variables. This means that a simple getter function now locks and unlocks a mutex, and I...

How do I make sure there is only 1 mutex?

Hi guys. I am running some thread safe code here. I am using a mutex to protect the section of code that needs to be run only by only 1 thread at a time. The problem I have is using this code sometimes I end up with 2 Mutex objects. This is a static function by the way. How do I make sure only 1 mutex object gets created?? /*static*/ My...

Why/How does a application keep mutex references created by another process?

I have this somewhat unusual process structure: Launch4J starts my Java application. It creates a mutex to provide single-instance functionality. The Java application starts a VB6 application. When the Java application terminates, the VB6 application is still running. (Desired behaviour) The problem is: The mutex created by Launch4J ...

C - Pthreads mutex and general headaches

Hey guys I was wondering if someone could provide a little help. I've been trying to teach myself pthreads and with that, mutex locks to get threads running together and using the same structure, whilst not reading and writing to bad data. My problem at the moment is, From my thread function, if i call a helper function that might loo...

Django: Simple rate limiting

Many of my views fetch external resources. I want to make sure that under heavy load I don't blow up the remote sites (and/or get banned). I only have 1 crawler so having a central lock will work fine. So the details: I want to allow at most 3 queries to a host per second, and have the rest block for a maximum of 15 seconds. How could ...

Get a list of mutex?

A program creates a mutex as part of its start-up. I don't know the format of this mutex so I wondered if there is a way to get a list of all non-abandoned mutex, open the program, get a new list and see if I can find the mutex by removing all duplicate entries. Is there a way to get this list? ...

Initialising an anonymous mutex-lock-holding class instance in the LHS of a comma operator

Suppose I have code something like this: #include "boost/thread/mutex.hpp" using boost::mutex; typedef mutex::scoped_lock lock; mutex mut1, mut2; void Func() { // ... } void test_raiicomma_1() { lock mut1_lock(mut1); Func(); } void test_raiicomma_2() { (lock(mut1)), Func(); } void test_raiicomma_3() { (lock(mut1)), (lock(mut2...

How can I have many threads that need to know the next ID to process and then increment that number safely?

I'm working a program that will have a bunch of threads processing data. Each thread needs to grab the next available ID, increment that ID by 1 for the next thread and do this in a thread-safe way. Is this an instance where I would use a mutex? Should I use a Queue.Synchronized instead and fill it up with all 300,000 ID's or is this ...

Pthreads in Mac OS X - Mutexes issue

I'm trying to learn how to program parallel algorithms in C using POSIX threads. My environment is a Mac OS X 10.5.5 with gcc 4. Compiling: gcc -Wall -D_REENTRANT -lpthread source.c -o test.o So, my problem is, if I compile this in a Ubuntu 9.04 box, it runs smoothly in thread order, on Mac looks like mutexes doesn't work and the thr...

Mutex for Rails Processes

When deploying Rails via Passenger or Mongrel you have multiple instances of the application running. What is the best practice or pattern to establish a mutex on shared resources such as a writing to a local file or to a remote file. I want to ensure two processes are not writing to the same resource at the same time. ...

Is mutex correctly implemented and how do I dispose it?

I am reviewing some code and one of the code analysis (fxCop) warnings has gotten me very confused. The code implements a few mutex's by creating variables at the start of the class, similar to this: private Mutex myMutex = new Mutex(); fxCop is popping up with a message saying that I must implement IDisposable for the class as the Mu...