Все вопросы: [mutex]

88 вопросов

похожие теги: boost-mutexrecursive-mutex
21
голосов
3ответов
31412 просмотров

What is the Mutex and semaphore In c#? where we need to implement?

What is the Mutex and semaphore in C#? Where we need to implement? How can we work with them in multithreading?

5
голосов
4ответов
3219 просмотров

Order of execution of waiting threads blocked by mutex

I have a mutex that controls access to a single object from multiple threads. When a thread has finished the mutex is unlocked to allow order threads to operate on the object. On Windows using the WaitForSingleObject function is there an order that threads are signaled? I want the first thread th...

45
голосов
6ответов
30278 просмотров

Do I need a mutex for reading?

I have a class that has a state (a simple enum) and that is accessed from two threads. For changing state I use a mutex (boost::mutex). Is it safe to check the state (e.g. compare state_ == ESTABLISHED) or do I have to use the mutex in this case too? In other words do I need the mutex when I just...

2
голосов
7ответов
364 просмотров

In an ISAPI filter, what is a good approach for a common logfile for multiple processes?

I have an ISAPI filter that runs on IIS6 or 7. When there are multiple worker processes ("Web garden"), the filter will be loaded and run in each w3wp.exe. How can I efficiently allow the filter to log its activities in a single consolidated logfile? log messages from the different (concurr...

8
голосов
1ответов
6323 просмотров

What happens if I ReleaseMutex() twice?

The Microsoft documentation is silent about what happens if I mistakenly call ReleaseMutex() when the mutex is already unlocked. Details: I'm trying to fix up some Windows code without having access to the compiler. I realise that WinApi mutexes are all recursive, and reference-counted. If I ...

57
голосов
6ответов
42366 просмотров

How are mutexes implemented?

Are some implementations better than others for specific applications? Is there anything to earn by rolling out your own?

2
голосов
2ответов
1715 просмотров

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

5
голосов
3ответов
3508 просмотров

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

2
голосов
3ответов
14604 просмотров

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

0
голосов
4ответов
165 просмотров

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

4
голосов
3ответов
848 просмотров

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

13
голосов
2ответов
23518 просмотров

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?

4
голосов
2ответов
1597 просмотров

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

1
голосов
2ответов
5059 просмотров

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

1
голосов
2ответов
904 просмотров

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

2
голосов
5ответов
1058 просмотров

How do I make sure there is only 1 mutex?

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

32
голосов
9ответов
29484 просмотров

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

13
голосов
3ответов
25481 просмотров

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

2
голосов
4ответов
711 просмотров

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

0
голосов
2ответов
94 просмотров

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) there 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 w...

2
голосов
3ответов
1796 просмотров

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

0
голосов
3ответов
1556 просмотров

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

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

8
голосов
3ответов
10240 просмотров

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

5
голосов
1ответов
850 просмотров

Why does MSDN sample from Threading Tutorial crash?

From sample example 4 of MSDN "Threading Tutorial" 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 Aut...

0
голосов
4ответов
463 просмотров

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 = @"...

35
голосов
7ответов
35727 просмотров

Ошибка утверждения мьютекса pthread

Я сталкиваюсь со следующей ошибкой в ​​непредсказуемое время в коммуникационном приложении на базе Linux (arm): pthread_mutex_lock.c:82: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed. Google обнаружил много ссылок на эту ошибку, но мало информации, которая кажется...

7
голосов
5ответов
6528 просмотров

Идеальный способ создания приложений с одним экземпляром на Mac

В Windows обычной практикой является создание именованного мьютекса и использование его наличия для определения того, что экземпляр данного приложения уже запущен. У этого есть свои недостатки, но в основном это работает. Я могу придумать, как это сделать на Mac: именованные мьютексы pthr...

51
голосов
3ответов
41228 просмотров

Различия между условными переменными, мьютексами и блокировками

Например, интерфейсы c ++ 0x Мне трудно понять, когда использовать какие из этих вещей (cv, mutex и lock). Кто-нибудь может объяснить или указать на ресурс? Заранее спасибо.

2
голосов
2ответов
3815 просмотров

Мьютекс в Python Twisted

Я использую платформу Twisted и получаю RPC асинхронно. У меня есть еще одна функция, которая выполняет задачу каждые 2 секунды и спит между ними. Это вызывается через response.callInThread. Они зависят от общих ресурсов, поэтому мне нужен потокобезопасный способ доступа к ним. Как можно использ...

1
голосов
2ответов
1581 просмотров

Как избежать нескольких экземпляров приложения?

У меня есть приложение myprogram.exe, которое вызывает функции и код внутри dll. Одна из этих функций, вызываемых myprogram.exe, создает новый экземпляр формы winform, MyForm.cs, а затем показывает это с помощью form.show () ;. У меня может быть n запущенных экземпляров «myprogram.exe», но я ...