Questions tagged [mutex]

A mutex ("mutual exclusion") is a mechanism to ensure integrity when the same data or resource is accessed (in particular, changed) concurrently from several threads.

A mutex ("mutual exclusion") is a mechanism to ensure integrity when the same data or resource is accessed (in particular, changed) concurrently from several threads.

Usually when the term mutex is used, it refers to a synchronisation primitive functionally identical to a binary semaphore. As OS-level synchronisation is often rather expensive due to context switching, busy-wait solutions based on atomic operations (e.g. mutex or critical section) exist.

See also:

4640 questions
2
votes
1 answer

Mutex with MongoDB

I have multiple servers sharing a common mongodb. In the DB there is a list of jobs, the servers have to finish. As I want to divide the load over all servers and want to avoid multiple servers doing the same job, I want to "Lock" that job. My Idea…
Tobi
  • 1,175
  • 1
  • 19
  • 44
2
votes
1 answer

How do Operating Systems schedule multiple threads on multiple CPU cores simultaneously?

I'm currently reading Tanenbaum's Modern Operating Systems and have a question about Gang- or Co-Scheduling: It's stated that an Operating Systems code is divided into logical parts by Mutexes to allow different parts of the OS to be executed…
Kaputnik120
  • 120
  • 10
2
votes
0 answers

Why Mutex doesn't guarantee unique instance randomly?

I use mutex to make sure that only one instance of my program is running on a server. Mutex mutex = new Mutex(false, Common.MutexName); if (!mutex.WaitOne(1000, false)) { Console.WriteLine("Another process is already…
daxu
  • 3,514
  • 5
  • 38
  • 76
2
votes
2 answers

Releasing a named mutex created in WPF Application.OnStartUp(): Which thread owns it?

I create a mutex within the OnStartup Method of a WPF app. The mutex is not used anywhere else in the program, its only purpose is to prevent certain programs from running concurrently. How can I release this mutex when the application…
HugoRune
  • 13,157
  • 7
  • 69
  • 144
2
votes
2 answers

synchronizing access to allocated memory

Is there a way to synchronize access to each element in an allocated memory. For example, if I allocate memory using the following code int* counters = new int[10]; is there a way to synchronize modification of each counter separately (being able…
WhatIf
  • 653
  • 2
  • 8
  • 18
2
votes
0 answers

Can batch or Windows cmd file create or release mutex?

Can batch or Windows cmd file create or release mutex, without custom exe? Similar questions (like this) tell only to write custom c exe. Can I work with mutex from bare batch script, or only with use a some Windows standard utils? UPD I do not need…
Y.N
  • 4,989
  • 7
  • 34
  • 61
2
votes
1 answer

Should the mutex operation throw a system_error for locking twice?

Here is the code mutex mtx; try{ mtx.lock(); mtx.lock(); }catch(system_error& e){ mtx.unlock(); cout << e.what() << '\n'; cout << e.code() << '\n'; } An output device or resource busy, generic: 16 is expected but never seen. gcc…
Milo Lu
  • 3,176
  • 3
  • 35
  • 46
2
votes
1 answer

C and pthreads: how can a mutex be referred to a particular variable?

In this code an example of the use of mutex is showed. In particular, the mutex is first declared before the main: pthread_mutex_t mutexsum; The particular variable to be "protected" by the mutex is dotstr.sum in the global structure dotstr: every…
BowPark
  • 1,340
  • 2
  • 21
  • 31
2
votes
1 answer

Using threads in C. Getting unexpected results

I am just new to threads in C. So starting with the very basics. I am just trying to create threads and using mutual exclusion on them. I have declared three function and creating 3 threads for them but every time I execute my program not all three…
Abhishek Gangwar
  • 1,697
  • 3
  • 17
  • 29
2
votes
2 answers

Forcing class methods use setter/getter of its own private member

Below is a very simple example of a class. This class is used in a multi-threaded system and I want to ensure that every access to _x (also in a future extensions of the class by other developers) will be protected by mutex. One way doing so, is to…
Sanich
  • 1,739
  • 6
  • 25
  • 43
2
votes
2 answers

*nix System-wide threads and processes mutex

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…
Metiu
  • 1,677
  • 2
  • 16
  • 24
2
votes
1 answer

crash in std::map clear() - multithreading

I'm facing with a strange crash in a multithreaded application: static std::map g_params; Thread 1 (void)lock(map_mutex); g_params[iParamID] = sValue; (void)unlock(map_mutex); Thread 2 (void)lock(map_mutex); …
2
votes
1 answer

How to use Thread Pool and Mutex in c#?

I try to learn how to use Thread Pool and Mutex, as a practice I'm trying to make an application that copy files from one path in the computer to another path in the computer. To do this application I used Thread Pool (so a few copies could happen…
ShaqD
  • 63
  • 1
  • 10
2
votes
2 answers

Error C2280 mutex in a class C++

I'm having an issue with declaring a mutex in a class, whenever I attempt instantiate the class the Error C2280 appears. My project is too create a simulation of the Dining Philosopher's Problem. Declaration: class Fork { public: struct…
Alex L
  • 115
  • 11
2
votes
1 answer

Suitable thread "fence" for a worker thread

I have a Worker class that runs its own thread to do some work in parallel. During specific intervalls I want it to be idle. I have an interface class Worker { mutex m_wait; void pause() { m_wait.lock(); } void continue()…
WorldSEnder
  • 4,875
  • 2
  • 28
  • 64
1 2 3
99
100