mutex Questions

3

Solved

I'm trying to find the equivalent of a critical section for C++11 , is the new C++11 mutex concept process-bound (e.g. enforces mutex only on the user-space) ? Perhaps it's implementation specific ...
Floaty asked 7/5, 2014 at 13:47

4

Solved

I know, I know, the title of my message may seem provocative, since boost::mutex purposefuly do not expose lock / unlock (in order to avoid dead locks). However the boost documentation is quite s...
Telemetry asked 15/12, 2009 at 1:35

2

Solved

All, Referring to the question in std::lock still caused deadlock I still couldn't figure what is the problem in the below code. Can somebody please explain the problem and how to fix this? Why do...
Sniffle asked 21/11, 2019 at 10:12

1

Solved

Consider the following code, with adjacent mutex sections containing shared memory accesses: std::mutex mutex; int x; void func() { { std::lock_guard lock{mutex}; x++; } { std::lock_guard lo...
Captor asked 22/6 at 13:0

1

Solved

Recently I installed the latest Visual Studio 2022 v17.10 to build my programs, and initially all went well. But after some other program installation, my programs started failing immediately on st...
Ermelindaermengarde asked 9/6 at 9:28

1

Solved

does c++ std::mutex get poisoned when a thread holding a lock gets terminated abruptly. If so, how do I recover that mutex in another thread?
Solid asked 6/6 at 10:55

8

Solved

I have to restrict my .net 4 WPF application so that it can be run only once per machine. Note that I said per machine, not per session. I implemented single instance applications using a simple mu...
Deville asked 19/11, 2010 at 7:50

3

Solved

I need two threads to progress in a "tick tock" pattern. When implmented with a semaphore this looks fine: Semaphore tick_sem(1); Semaphore tock_sem(0); void ticker( void ) { while( true ) { P...
Bet asked 23/7, 2011 at 23:51

1

I am a bit confused on the status of synchronized_value, on one hand it is suggested in CppCoreGuidelines, but on the other it is not available in C++20, there is not even a boost version (there is...
Chapbook asked 14/9, 2020 at 10:17

2

Solved

I'm a go-newbie, so please be gentle. So I've been using mutexes in some of my code for a couple weeks now. I understand the concept behind it: lock access to a certain resource, interact with it...
Shuttering asked 22/6, 2019 at 21:39

4

Solved

I have seen some people hate on recursive_mutex: http://www.zaval.org/resources/library/butenhof1.html But when thinking about how to implement a class that is thread safe (mutex protected), it s...
Caulk asked 24/1, 2013 at 10:19

37

Is there any difference between a binary semaphore and mutex or are they essentially the same?
Misspend asked 15/9, 2008 at 13:23

7

Some time ago had an interview and was asked to implement Semaphore by using mutex operations and primitives only (he allowed int to be considered as atomic). I came with solution below. He did not...
Libel asked 12/12, 2013 at 4:0

1

The following code leads into an increasing usage of memory: #include <shared_mutex> class foo { public: void bar() { std::unique_lock lock(m_mtx); } std::shared_mutex m_mtx; }; int m...
Perilymph asked 14/5, 2019 at 14:21

13

Solved

How do i tell if one instance of my program is running? I thought I could do this with a data file but it would just be messy :( I want to do this as I only want 1 instance to ever be open at one ...
Nez asked 19/1, 2009 at 23:7

1

I'm testing edge cases with std::condition_variable and I tested scenario to starve one thread. Scenario is that there are 99 producers and only one consumer, all of them working on 1 queue with ma...
Steatopygia asked 10/11, 2023 at 8:59

3

Solved

I know that threading.Lock() is equal to threading.Semaphore(1). Is also threading.Lock() equal to threading.BoundedSemaphore(1) ? And newly I saw threading.BoundedSemaphore(), what is the differen...

5

Solved

I am trying to solve a big numerical problem which involves lots of subproblems, and I'm using Python's multiprocessing module (specifically Pool.map) to split up different independent subproblems ...
Campbell asked 19/11, 2012 at 1:13

1

i'd like to gain understanding why following seems to not work properly in Rust. I'd like to chunk a vector and give every thread a chunk to work on it. I tried it with a Arc and a Mutex combinati...
Gorizia asked 2/4, 2020 at 15:10

1

My environment: Windows Server 2012 R2 with Remote Desktop Services installed on it. Programming with C Problem: User U1 connects to the Windows Server via RDP and creates a global mutex (Cr...
Ushas asked 28/6, 2018 at 9:9

1

I am trying to return a struct containing reference to a shared mutex: struct Test<'a> { mutex: Arc<Mutex<()>>, guard: &'a MutexGuard<'a, ()>, } impl<'a> Test&l...
Lukewarm asked 21/1, 2022 at 19:42

2

Solved

In the question How to use std::atomic<>, obviously we can just use std::mutex to keep thread safety. I want to know when to use which one. struct A { std::atomic<int> x{0}; void Add(...
Wooden asked 21/9, 2016 at 12:56

9

Solved

I think both are doing the same job,how do you decide which one to use for synchronization?
Remontant asked 3/5, 2011 at 13:1

2

Is there a way I can tell std::lock_guard to call try_lock instead of lock when it acquires the mutex? The only way I could think of is to use std::adopt_lock: if (!_mutex.try_lock()) { // Handle ...
Dumps asked 29/11, 2015 at 8:31

3

Solved

I am a bit confused about the role of std::unique_lock when working with std::condition_variable. As far as I understood the documentation, std::unique_lock is basically a bloated lock guard, with ...
Bonar asked 27/10, 2012 at 11:14

© 2022 - 2024 — McMap. All rights reserved.