stdmutex Questions

1

Solved

I have two threads that work the producer and consumer sides of a std::queue. The queue isn't often full, so I'd like to avoid the consumer grabbing the mutex that is guarding mutating the queue. I...
Sinecure asked 16/5, 2022 at 14:10

1

Solved

Ran the following in Visual Studio 2022 in release mode: #include <chrono> #include <mutex> #include <shared_mutex> #include <iostream> std::mutex mx; std::shared_mutex smx...
Espousal asked 16/11, 2021 at 13:49

1

Solved

[thread.mutex.class]/3: [...] It is a standard-layout class ([class.prop]). What is the reason for this requirement?
Gibun asked 3/11, 2021 at 14:50

2

Solved

Following static_assert passes in both gcc and clang trunk. #include<mutex> int main(){ static_assert(sizeof(std::mutex)==40); } Since x86 CPUs have 64 byte cache line I was expecting mutex...
Secern asked 2/10, 2020 at 11:7

7

Solved

I have two use cases. A. I want to synchronise access to a queue for two threads. B. I want to synchronise access to a queue for two threads and use a condition variable because one of the threads ...
Carpology asked 11/12, 2013 at 10:35

4

The pthread_mutex_init() function returns a non-zero value when it fails to initialize the mutex, while the std::mutex class in C++11 has a constructor of noexcept. Say one chooses to implement a...
Tact asked 9/2, 2018 at 2:51

2

Solved

I am wondering how can std::atomic_ref be implemented efficiently (one std::mutex per object) for non-atomic objects as the following property seems rather hard to enforce: Atomic operations app...
Hungarian asked 11/10, 2019 at 17:54

3

I have a scenario where the shared memory area is exclusively accessed by two different processes. When I launch the processes, the first process successfully locks the mutex, updates the memory an...
Epitomize asked 10/10, 2017 at 9:15

1

It seems like CRITICAL_SECTION performance became worse on Windows 8 and higher. (see graphs below) The test is pretty simple: some concurrent threads do 3 million locks each to access a variable ...
Morley asked 4/9, 2018 at 16:38

1

Solved

Is the get_a() function safe for race-conditions or do I need to explicitly copy str_ as in get_b() in order to have a thread-safe function? class Class { public: auto get_a() -> std::st...
Origami asked 4/12, 2018 at 13:4

1

Solved

Take this simple function that increments an integer under a lock implemented by std::mutex: #include <mutex> std::mutex m; void inc(int& i) { std::unique_lock<std::mutex> lock(...
Flourish asked 22/9, 2017 at 16:54

1

I have defined a class that has std::mutex my_mutex as its private member variable. But when I try to use it using lock_guard in a member function which is called from different threads, the compil...
Odawa asked 19/9, 2017 at 8:18

2

I've seen most examples using std::mutex where the mutex is global. I was wondering is there any specific reason why this is done? I've had programs of my own where I don't do this, and simply pass...
Attune asked 5/7, 2017 at 17:37

4

Solved

I started using std::mutexes to stop a thread and wait for another thread to resume it. It works like this: Thread 1 // Ensures the mutex will be locked while(myWaitMutex.try_lock()); // Locks it...
Frodi asked 28/4, 2017 at 8:51
1

© 2022 - 2024 — McMap. All rights reserved.