Mutexes in Win32
how does a mutex can be shared between processes? does it mean a different .exe process? ...
how does a mutex can be shared between processes? does it mean a different .exe process? ...
Code: #include <iostream> #include "stdafx.h" #include <boost/thread.hpp> #include <boost/thread/mutex.hpp> using namespace std; boost::mutex mut; double results[10]; void doubler(int x) { //boost::mutex::scoped_lock lck(mut); results[x] = x*2; } int _tmain(int argc, _TCHAR* argv[]) { boost::thread_group thds; for (int x = 10; x>0...
Hey i want to create a mutex with the kernel function NtCreateMutant. I did it like this: Handle hMutex; NTSTATUS ntMutex = NtOpenMutant(&hMutex,MUTEX_ALL_ACCESS,false); the NTSTATUS value that is returned: C0000024 STATUS_OBJECT_TYPE_MISMATCH hope someone can help me with calling NtOpenMutant the right way. With the windows API O...
Hi. I'm having some trouble with a program using pthreads, where occassional crashes occur, that could be related to how the threads operate on data So I have some basic questions about how to program using threads, and memory layout: Assume that a public class function performs some operations on some strings, and returns the result ...
How to get PIDs of processes that are using a given file name and mutex name? (Not by custom kernel driver, but in C# in user mode.) UPDATE: Thanks to Daniel Renshaw I found a script that lists all handles with PIDs. (Using a not undocumented and unfrozen functions.) ...
How can I find from mutex handle in C# that a mutex is acquired? When mutex.WaitOne(timeout) timeouts, it returns false. However, how can I find that from the mutex handle? (Maybe using p/invoke.) UPDATE: public class InterProcessLock : IDisposable { readonly Mutex mutex; public bool IsAcquired { get; private set; } publ...
Hi all, I'm trying to use a faster memory allocator in C++. I can't use Hoard due to licensing / cost. I was using NEDMalloc in a single threaded setting and got excellent performance, but I'm wondering if I should switch to something else -- as I understand things, NEDMalloc is just a replacement for C-based malloc() & free(), not th...
I am having a problem with mutexes (pthread_mutex on Linux) where if a thread locks a mutex right again after unlocking it, another thread is not very successful getting a lock. I've attached test code where one mutex is created, along with two threads that in an endless loop lock the mutex, sleep for a while and unlock it again. The ou...
Are there locks in Linux where the waiting queue is FIFO? This seems like such an obvious thing, and yet I just discovered that pthread mutexes aren't FIFO, and semaphores apparently aren't FIFO either (I'm working on kernel 2.4 (homework))... Does Linux have a lock with FIFO waiting queue, or is there an easy way to make one with exis...
Hi, The problem I am seeking some help for is written in point no. 7. Before that, I describe the structure of my code. From main(), two threads thread1 and thread2 are created and initialized to two functions fun1() and fun2() respectively. I have a mutex named lock_mutex and condition variables named cond1, cond2, cond3 and cond4. I ...
Hello, I was wondering whether it would ever make sense to use a mutex or semaphore when there is only one thread?. Thanks for your help. ...
I am fairly new to pthread programming and am trying to get my head around cond_signal & mutex_lock. I am writing a sample program which has One producer thread and Two consumer threads. There is a queue between producer and the first consumer and a different queue between producer and the second consumer. My producer is basically a co...
I am using a third-party C++ library (OpenFst), which is not particularly designed to be thread-safe. It does have some unused Mutex classes in there, though. Now I would like to call some functions from that library and run them in Boost threads. How can I do that? Do I just have to write additional Mutex classes? In particular, some ...
Can someone help me out with example of a situation in which absence of mutexes "definetely" leads to incorrect result. I need this so that I could test my mutex implementation. -- Neeraj ...
I have a C# app that creates a mutex: var mutex = new Mutex(true, // desire initial ownership "MyMutexName", out owned); How would an unmanaged C++ app detect when this mutex is released? (I'm not a C++ dev) Thanks in advance, Jim ...
Hi, There is scenario, i have two threads both are using same mutex. One thread locked the mutex and crashed. What would be the mutex state? It still locked and second thread never own that mutex? Means a deadlock situation? Thanks in advance. ...
I have some resource which I'd like to protect from concurrent usage both by threads in the same process and among different processes. What is the "right" way of doing it in *nix? E.g. we want to write to a file from a multithreaded app, which once in a while forks some subprocesses. How to ensure that each thread has exclusive access ...
My application needs to behave slightly differently when it loads if there is already an instance running. I understand how to use a mutex to prevent additional instances loading, but that doesn't quite solve my problem. For example: Instance 1 loads, gets the mutex. Instance 2 loads, can't get the mutex, knows there's another instan...
I'm re-working a Java executable that may be started multiple times, and I want the process to proceed one at a time. In C# I would do this with a named/system Mutex, but this doesn't seem to be possible in Java. How can I achieve this functionality? ...
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <semaphore.h> #define WORK_SIZE 1024 pthread_mutex_t work_mutex; char work_area[WORK_SIZE]; void *thread_start(void *); int main() { pthread_t a_thread; pthread_mutex_init(&work_mutex,NULL); pthread_create(&a_thread,NULL,thread_st...