4,817 questions
0
votes
0
answers
128
views
Is this protection method multithread safe?
I've written a MQTT client for embedded system with RTOS (understand not POSIX, generally FreeRTOS). There's no pthread in the system. There's only 32 bits atomic instructions supported.
The client ...
-4
votes
1
answer
121
views
A global sync.Mutex don't work with multiple client packages?
I have a package "tools" that expose a method that must execute some logic only one time. The next calls don't do nothing.
The file tools/tools.go is like:
package tools
import (
"...
1
vote
0
answers
51
views
Why use a delay time less than portMAX_DELAY when waiting for a semaphore/mutex/queue FreeRTOS?
First I want to make sure I'm understanding the behavior of what is happening when trying (and failing) to take a semaphore or mutex...
When this code runs (assuming xSemaphoreTake is going to fail to ...
3
votes
2
answers
162
views
c++ mutex with different data in the critical section
class MyTest {
void getter() {
std::unique_lock lock(mutex_);
if (!set_) {
cout << "set already" << endl;
}
lock.unlock();
// question ...
3
votes
1
answer
160
views
Copying heap allocated memory in multiple threads... Is a mutex required or is it safe?
Environment is Ubuntu 24.04, QT Creator 6, g++ 13.3, pthreads.
Given the following code (error handling has been removed for readability):
#include <iostream>
#include <thread>
#include &...
4
votes
1
answer
153
views
c++ mutex and memory barrier
class MyTest {
void getter() {
std::unique_lock lock(mutex);
if (!set_) {
cout << "set already" << endl;
...
6
votes
2
answers
208
views
C++ pointers and concurrency
I need some help for understanding general basics of shared resource access in C++ multithreading.
When I need some variable that must be accessible for several threads, I declare it as atomic, or ...
3
votes
1
answer
97
views
munmap shared memory with locked robust mutex makes it deadlock, why?
I need to use robust mutexes for IPC in case one of my processes crashes while holding a mutex locked. Definition is clear from e.g. man pthread_mutexattr_setrobust and I will not repeat it here.
I ...
2
votes
0
answers
60
views
Python (with Kivy) app using buildozer crashes on Android 14/15 with pthread_mutex_lock called on a destroyed mutex in SDLActivity
Title
Android 14/15 crash with Kivy + Buildozer: pthread_mutex_lock called on a destroyed mutex (SDLActivity)
Problem Description
I'm building a Python game using Kivy, packaged for Android via ...
1
vote
0
answers
361
views
Python mutex.cc lock issue
I have a python program that hangs in a library call on this message:
[mutex.cc : 452] RAW: Lock blocking 0x6000009e1158 @
I started the program with trace to see what is going on, and I get (a lot ...
0
votes
2
answers
352
views
Sleeping Barber problem: how to prevent the barber from cutting before the customer is ready?
Recently, I've been studying the classic Sleeping Barber problem and came across a possible solution from Wikipedia:
# The first two are mutexes (only 0 or 1 possible)
Semaphore barberReady = 0
...
2
votes
0
answers
195
views
How to implement unique_lock for multiple mutexes
<mutex> contains different RAII wrappers:
lock_guard - single mutex, always locked
unique_lock - single mutex, can defer or try
scoped_lock - many mutexes, always locked, supersedes lock_guard ...
2
votes
1
answer
117
views
Strange behaviour of atomicCAS when used as a mutex
I'm trying to learn CUDA programming, and recently I have been working on the lectures in this course: https://people.maths.ox.ac.uk/~gilesm/cuda/lecs/lec3.pdf, where they discussed the atomicCAS ...
1
vote
2
answers
109
views
Sequence of Events in : mutex.unlock() vs returning from a function
short brief - I want to understand the sequence of event when returning from a function and unlocking a mutex in the same function.
helper macro: to print to screen
#define TRACE() {std::cout <&...
0
votes
1
answer
72
views
Windows CreateMutexW using Python not working
I'm writing a Python application that connects to an external device. I want to enable the user to operate multiple devices simultaneously by running multiple instances of the application, but each ...
4
votes
1
answer
103
views
When exactly does a robust POSIX mutex that returns EOWNERDEAD get locked?
I know that, for POSIX shared and robust mutexes, if the process holding them crashes, the next process trying to acquire the lock will successfully call pthread_mutex_lock, which will return ...
4
votes
1
answer
114
views
Is the following lifetime shortage conversion sound?
I know that Mutex is an invariant Rust type, so Mutex<&'a T> cannot be converted to Mutex<&'b T> even if 'a outlives 'b.
In my code I want to convert Arc<Mutex<&'a mut T&...
0
votes
1
answer
85
views
Does sharing an unit type across threads need any synchronization?
Since unit type () in Rust occupies 0 bytes, basically to which nothing can be written or read from. So, is synchronization really required for sharing unit types across threads using Arc and Mutex?
1
vote
0
answers
60
views
Is there a reason not to replace the default logging.Handler lock with a multiprocessing.RLock to synchronize multiprocess logging
I've got some code that, for reasons not germane to the problem at hand:
Must write very large log messages
Must write them from multiple multiprocessing worker processes
Must not interleave the logs ...
1
vote
3
answers
136
views
Why is the lock in Rust held throughout the `if let` block? [duplicate]
Call Mutex.lock() after if let. This lock will be held inside the whole if let block.
If we lock again in the if let block. It's deadlock. This also happen for RwLock.
use std::sync::Mutex;
fn main() {...
0
votes
0
answers
104
views
Mutex Implementations and Memory Fences in C
I have been writing my own x86 32-bit operating system for the past month or so. My system uses just one core.
Anyway, I have been reading a lot about memory fences, CPU optimizations, and compiler ...
24
votes
6
answers
5k
views
Why use a mutex and not a semaphore?
Looking in cppreference, it seems to imply a std::binary_semaphore may be more efficient than a std::mutex.
Is there any reason not to use a std::binary_semaphore initialized to 1 instead of a std::...
1
vote
0
answers
51
views
Locking a json file across 2 independent processes - a comparison of two methods
(I know that this question has come up several times on Stack Overflow already, but I still think it is worth clarifying some details.)
Suppose that there are two independent Python processes: a.py ...
4
votes
0
answers
143
views
Using a mutex to restore an application hidden in the system tray results in the window's minimize button becoming non-functional
In Rad Studio 12 C++ (Delphi/C++Builder), using VCL.
I'm facing an issue in my application where the minimize button becomes don't working after restoring the main window from the system tray by a ...
1
vote
0
answers
184
views
LVGL UI Freeze on ESP32: lv_tick_task Stuck with Mutex Held
I'm encountering an issue with my ESP32 project using LVGL for UI rendering. After running for about 30 minutes, the entire UI freezes. After some debugging, it seems that the freeze is due to my ...
0
votes
0
answers
51
views
Problem with synchronise changes textures in SDL
I want to make sure that I have visualization in one stream and all calculations in the other, I need some changes to be visible during the calculations, for this I wanted to change the variables ...
0
votes
1
answer
60
views
Code after suspended function call not executed in Kotlin coroutine
I'm using Kotlin coroutines to manage a TLS socket connection. In my minimal version of sendMessageToServerTest, I call connectTest() when the socket is not connected, then log the result. However, ...
0
votes
2
answers
124
views
Pass a command line argument to a running instance of Winform Application
I need to ensure only 1 instance of the application is running. So I have a Mutex lock code in the Main() method which works fine.
now I have a requirement to pass a command line argument to the ...
0
votes
1
answer
65
views
Why does a global lock perform better than total ordering locking in this concurrency benchmark?
I'm working on a homework question (end of this PDF): https://pages.cs.wisc.edu/~remzi/OSTEP/threads-bugs.pdf
Code: https://github.com/remzi-arpacidusseau/ostep-homework/tree/master/threads-bugs
In ...
1
vote
1
answer
80
views
Why can't I catch AbandonedMutexException after a task
I was expecting to trigger a AbandonedMutexException after a task that does not release the mutex, the program stuck when WaitOne after the task:
Mutex mutex = new();
BankAccount account = new();
...
2
votes
2
answers
173
views
C, Using 2 threads with mutex and conditional variable to print A0B1A2B3A4B5A6B7A8B9
So I have this lab problem where I need to use 2 threads with mutex and cond var to print the title pattern. The pattern is stored in an array of char, and there's a global keeping track of which ...
1
vote
1
answer
62
views
Leaks when using pthread_detach
I'm working on Philosopher.
The Philosophers project involves simulating the behavior of several philosophers sitting around a table, sharing forks to eat. The aim is to implement this simulation ...
2
votes
1
answer
133
views
can spinlocks in signal handlers cause deadlock?
I've read that using a mutex in a signal handler can cause deadlock if a thread of the main program has locked the mutex before the signal handler is invoked. I've also read suggestions that signal ...
1
vote
0
answers
82
views
Managing Worker Thread Wake-Up in C++: Separate vs. Shared Condition Variables?
I have a queue of worker thread IDs in C++, and a coordinator thread wakes each thread in order. The woken thread then interacts with the coordinator thread to perform some work. Once done, the ...
6
votes
4
answers
229
views
Difference between if statement initializers taking a lock
I need to get a lock only during evaluation of the if statement condition.
The lock must be released when running the code inside the if or else statements.
I found a piece of code and I don't know if ...
0
votes
1
answer
80
views
Mutex release on demand
I am creating a program that consists of WebsocketReader, which reads data from a websocket (basically runs a loop to read out the newly incoming data), and ConfigurationFetcher, which needs to ...
1
vote
0
answers
97
views
Semaphore incrementation from inside SIGINT handler produces weird behavior
I am trying to set up SIGINT signal handler to wake up the main thread via binary semaphore. For that, as I attach below, I set up a SIGINT handler to run handler() function which just increments ...
0
votes
2
answers
205
views
Why can't I assign an std::optional of std::lock_guard?
Why can't I declare an optional std::lock_guard and then assign it later? The same thing with an optional string works just fine.
This works:
std::mutex m;
std::optional<std::lock_guard<std::...
2
votes
1
answer
96
views
Why does this mutex that protects globally unique instantiations deadlock when attempting to create an already existing element?
This program hangs and I suspect it does not release the mutex lock as it is supposed to. I must be doing something wrong here, but I cannot put my finger on it.
use std::any::TypeId;
use std::...
1
vote
1
answer
49
views
Synchronization using condition_variable
There is such an interesting little code (I'll take the most important thing, since my project is quite large
void RunForever(int time_out)
{
int criticalSize = 3;
...
-1
votes
1
answer
97
views
Is creating a mutex the same as waiting on it?
I need a global mutex to ensure only one instance of my application can run at a time.
I found the following code on SO:
using var mutex = MutexAcl.Create(true, mutexId, out bool mutexCreated, ...
2
votes
1
answer
132
views
(c++ thread and condition_variable) Could this program never end forever?
I think the source code below may not end forever.
Assume that all waiter threads have entered the wait state.
After that, waker call notify_all()
One thread, t1, wakes up and does something. And ...
-3
votes
2
answers
147
views
What is the best way to make a parent thread wait after initializing a child pthread until it receives some signal from the child?
Immediately after spawning a thread with pthread_create, I would like the parent to wait an arbitrary amount of time until the child thread allows it to continue. Here is how I might approach it with ...
0
votes
1
answer
67
views
Match lock deals with deadlocks caused by long-term tasks
I am confused by the results of running the following code. I can understand the logic of the behavior, but it seems a bit unreasonable to me (because I think it makes the variable lifetime confusing)
...
2
votes
1
answer
76
views
System.ArgumentNullException on new MutexAccessRule
I have a "single application instance" detection function, using the "classic" Mutex approach:
var identity = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var ...
0
votes
1
answer
70
views
How to properly close a QWidget created on an other thread? [OBS Source Plugin]
I am trying to make a plugin for OBS Studio that will add a custom source type object.
OBS provide a simple way to let the user display and change the source properties with the function ...
0
votes
1
answer
119
views
Why does kotlinx.coroutines.sync.Mutex appear to block system level threads?
Kotlin document states that Mutex is for synchronizing co-routines, not System-level threads:
The key difference is that Mutex.lock() is a suspending function. It does NOT block a thread. - kotlin ...
-2
votes
2
answers
208
views
what is the scope of a c++ mutex lock guard?
I'm trying to figure out the scope of mutexes and mutex lock_guard and no one has been able to explain it to me. Consider the following c++ code:
void somefunction
{
std::lock_guard<std::mutex&...
0
votes
1
answer
124
views
How is it possible that I'm locking a mutex multiple times, if mutex shall be possible to be locked only once?
I'm trying to understand c++ semaphore and mutex, and I found out that I'm locking 1 mutex several times, or at least my debugging messages are showing that is the case.
Even though we have only 1 ...
2
votes
1
answer
63
views
MPSC-like queue failing with erroneous dequeue
Goal
Implement a MPSC-like queue with mutexes and sempahores.
Issue
Eventually, the consumer will attempt to dequeue an empty queue.
Minimal Reproducible Example
I have edited the question to include ...