In order to allow only a single instance of an application running I'm using mutex. The code is given below. Is this the right way to do it? Are there any flaws in the code?
How to show the already running application when user tries to open the application the second time. At present (in the code below), I'm just displaying a message t...
This blog post demonstrates a way to implement a mutex per string id idiom. The String ids used are to represent HttpSession ids.
Why do we need to wrap a WeakReference around the Mutex instances ? Isn't it better to just create a Map from String -> Mutex ?
Why do we need to call put twice ?
public Mutex getMutex( String id )
{ ...
This is an offshoot of this question but with a few constraints removed.
I have a system where I need to manage file locking. I need to be able to lock a file (shared read locking) in one thread and then unlock it in another. More accurately, I can't be sure what thread it will be unlocked in or even if the creating thread is still arou...
I have two instances running of same Windows Service. They check the health of each other and report if any issue is found. I have a critical job that needs to be performed so I am running it with a fail-over approach, it runs in Master, and if Master is not responding it runs in slave. This job needs to communicate over a specific seria...
I have 2 threads and a shared float global. One thread only writes to the variable while the other only reads from it, do I need to lock access to this variable? In other words:
volatile float x;
void reader_thread() {
while (1) {
// Grab mutex here?
float local_x = x;
// Release mutex?
do_stuff_wi...
What is the correct plural form of the portmanteau mutex. Is it mutexes or mutices?
...
Hi,
I have some very basic semaphore code that works great on Linux, but cannot for the life of me get it to run properly on OS X... It returns the oddest of results...
#include <iostream>
#include <fcntl.h>
#include <stdio.h>
#include <semaphore.h>
int main()
{
sem_t* test;
test = sem_open("test", O_CREAT, 0, 1);
int val...
The title says it all. In Windows environment, is Boost's scoped mutex using WinAPI's critical sections, or something else?
...
We have a static (singleton) class which will be used in a mutithreaded environment. We use mutex in its constructor and other mrmber functions. However there is no mutex for the destructor. Destructor do some tasks like cleaning up of some other member objetcs etc.
Do we need to a mutex in the distructor also ?
...
hey, sorry to be a bother, but I need help urgently. I searched for this before I posted this question.
I'm getting a segmentation fault when I try to do
pthread_mutex_lock(&_mutex).
This is really odd, I'm not sure what might have caused it. I have initialized _mutex in the constructor with
pthread_mutex_init(&_mutex,NULL).
anythi...
I'm using a Mutex to make sure a webservice is only running once at a time, but I can't get it 100% right with WaitOnce and ReleaseMutex.
I've got this:
private static Mutex mutex = new Mutex();
[WebMethod]
public bool TriggerAll()
{
bool ranJobs = false;
try
{
if (mutex.WaitOne(0, f...
I have two applications, a WinForms app and a Windows Service that will both run on the same machine. I want the WinForms app to reliably detect when the service is running. I have complete control over the design and implementation of both applications.
My first thought is to use a Mutex, instantiated by the Service and detectable by ...
Hi,
I'm doing IPC on Linux using boost::interprocess::shared_memory_object as per the reference (anonymous mutex example).
There's a server process, which creates the shared_memory_object and writes to it, while holding an interprocess_mutex wrapped in a scoped_lock; and a client process which prints whatever the other one has written ...
I have a multithreaded app that has to read some data often, and occasionally that data is updated. Right now a mutex keeps access to that data safe, but it's expensive because I would like multiple threads to be able to read simultaneously, and only lock them out when an update is needed (the updating thread could wait for the other thr...
Hi,
I'm working on a simulation that uses multithreading extensively. The thing is that, until now i've never used any mutex objects to protect my data. And the result, is that i'm getting bunch of segmentation faults..
I'm trying to lock/unlock with mutex while : reading/writing but that causes me another segfault :
#0 77D27DD2 ntdl...
Is there any downside to calling pthread_cond_timedwait without taking a lock on the associated mutex first, and also not taking a mutex lock when calling pthread_cond_signal ?
In my case there is really no condition to check, I want a behavior very similar to Java wait(long) and notify().
According to the documentation, there can be ...
I have an application, "myprogram.exe", which calls functions and code inside a dll, one of this functions that "myprogram.exe" calls create a new instance of a winform, "MyForm.cs" and then show it using form.show();.
I can have 'n' number of "myprogram.exe" instances running, but I want to have only one instance of "MyForm.cs" for eac...
I'm using the Twisted framework, and am getting RPCs asynchronously. I have another function which does a task every 2 seconds, and sleeps in between. This is called through reactor.callInThread. These depend on a shared resources, so I need some thread-safe way of accessing them. How does one go about using critical sections / mutexes /...
For example the c++0x interfaces
I am having a hard time figuring out when to use which of these things (cv, mutex and lock).
Can anyone please explain or point to a resource?
thanks in regard
...
On Windows, it's common practice to create a named mutex and use the presence of that to determine that an instance of a given app is already running. This has its drawbacks, but mostly works.
I can think of a ways to do this on the Mac:
named pthread mutexes
enumerate running processes and look for one that matches
create and lock a ...