4,817 questions
-2
votes
1
answer
72
views
Close Mutant handle
I found handle mutex using Process Explorer.
I can close it with this programm, then i'm able to launch second instance of PrivodBondar.exe.
With chatGPT help I wrote powershell script which closing ...
1
vote
3
answers
221
views
Safe for an object to return a lock on itself?
Is this code correct / advisable style? That is, is the lock being returned guaranteed to keep the mutex locked through the process of being returned , as opposed to say unlocking then re-locking (or ...
0
votes
0
answers
48
views
Violation of mutual exclusion?
I want to know if mutual exclusion is upheld for these 2 process'. Assuming everything is atomic
int ba = 0 , int bt = 0
Process D
while(true) {
D1: non critical section
D2a: if (bt = -1) {...
1
vote
0
answers
85
views
About threads and semaphore (POSIX semaphores)
I want every time a student is created to display who has been created and in which department they study. I'm stuck and I don't know what parameters to pass to printInfo(), do you have any idea? I ...
1
vote
1
answer
83
views
Ofstream-based class overwrites files
I have created a "File" class for a C++ project of mine, and its based on ofstream. Here is the simplified code:
file.h
#include <fstream>
#include <mutex>
#include <...
2
votes
1
answer
77
views
Mutex unlock in function argument blocks forever
This code completes right away (playground):
use std::sync::Mutex;
fn f(_: usize, _: usize) {}
fn main() {
let m = Mutex::new(0);
let i = { *m.lock().unwrap() };
let j = { *m.lock()....
4
votes
1
answer
97
views
Can javascript have race condition?
For the following code in javascript I want to know if there are concurrent api requests to increment count is there any possibility of a race condition considering the fact that javascript is single ...
0
votes
1
answer
198
views
tokio Mutex deadlocks in rust
for some reasons that one of my mutex causes "deadlock" in the code.
in the code below inside the ability.perform function the hero_clone which is a mutex is deadlocked and after using lock()...
1
vote
1
answer
82
views
The problem of mutex lock in parallel matrix multiplication calculation
I am designing a parallel matrix multiplication algorithm using the POSIX threads (pthread) library, which is an improvement on the CPU version of gpt.c by Andrej Karpathy.
First, I ran it directly ...
2
votes
2
answers
65
views
C++ Monitor mutex thread issue
This code should stop at 15 characters (line), but it does not and it keeps going infinitely. The main problem with this code is that the condition variable logic doesn't allow all threads to ...
2
votes
0
answers
47
views
Confirm the concurrent capabilities of this fair reader writer ticket lock
I'm writing a very simple, shared ticket lock whose goal is to be fair for both readers and writers in the order they arrive.
Everyone gets in the same line
Line-contiguous reader groups get ...
2
votes
1
answer
100
views
How to realize random access to the same GPU based resource in Vulkan (basically: how to create a "mutex")?
I am playing with calculating pictures of fractals using a GPU and Vulkan and "utilizing the power of compute shaders".
There I ran into one problem and could not really find a satisfying ...
1
vote
0
answers
32
views
Linux c mutex memory errors and leak [duplicate]
I define a pthread_mutex_t in a shared object library, initialize it in a process and use it in a function of the library. Following the structure of the code. With processes I mean separated running ...
0
votes
2
answers
98
views
mutate dynamically sized vec in parallel
I'm trying to mutate a dynamically sized (i.e. under certain conditions, new values are pushed, and pop() gets called in every iteration) Vec in parallel. Am I doing anything wrong in this working ...
0
votes
0
answers
54
views
How to diagnose a serial communication crash that happens randomly and very seldom?
I'm connecting to a Lakeshore 336 Temperature controller from Linux Mint via pyserial. My app works relatively well and has operated for months at a time without error. However, it sometimes happen ...
1
vote
1
answer
165
views
Embedded C avoid optimization when copy global variable to stack variable in critical section
I am working on the RTOS support in our SW components.
There are some scenarios when it makes sense to create a copy of global variables into local variables in a critical section (e.g. protected by ...
-2
votes
1
answer
157
views
Possible Thread Starvation in C++
I have a decode function that decodes a string and internally uses a map to store already-decoded values for efficiency. This function is accessed by multiple threads (using pthread), so to prevent ...
0
votes
1
answer
147
views
Rust function that returns a value inside a Mutex<Option<T>>
I have a bunch of functions in my rust app that all get a Mutex as a parameter, which holds an Option. I need that Mutex because the functions will be executed in threads, and I need the Option ...
1
vote
1
answer
171
views
Question about condition_variable, why condition_variable is paired with mutex [duplicate]
I have been learning std::condition_variable recently and there is just some question that I cannot understand.
Cppreference and many other tutorials give example like this:
std::mutex m;
std::...
1
vote
1
answer
75
views
On shared_ptr use_count of resource pool C++ std::shared_ptr
I want to construct a resource pool which maintains a set of resources shared between several threads. Each thread pops a resource from the pool, uses it to perform some work and pushes the resource ...
1
vote
1
answer
78
views
Python single thread performance vs main thread performance
I was experimenting with pythons multiprocessing and threading modules and, stumbled upon something rather strange.
have a look at the following program:
import threading
import time
import ...
1
vote
1
answer
87
views
May this function case thread to wait indefinitely?
I am reading the code in flutter engine at
https://github.com/flutter/engine/blob/main/shell/common/platform_view.cc#L58
I want to ask that if latch.Signal() is reached before latch.Wait(), will it ...
0
votes
0
answers
39
views
github runner produce unreliable executables when using unique_lock<std::mutex> [duplicate]
I'm facing a serious issue when deploying executables built by Windows GitHub runners: any executable that uses std::unique_lock<std::mutex> is unreliable! It compiles correctly, but will ...
2
votes
0
answers
63
views
How do atomics vs mutexes differ in terms of cacheline synchronization
I know there are many discrepancies between them, e.g., atomics may incur spinning while mutexes may involve blocking.
But what I want to know is how they differ in terms of cacheline synchronization.
...
0
votes
1
answer
74
views
multithreading in c++ not working properly
I am trying to run two threads. The first one will run infinitely and the other one will run when mutex lock on first will be cleared.
I don't want to change the basic structure of code like, the loop ...
1
vote
0
answers
161
views
TSAN WARNING: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread)
I have write the following member function in my class which executes in a seperate thread and it sets the _cancellationRequested to true and execution function which runs in a seperate thread detects ...
0
votes
1
answer
74
views
Seeking Improved Solutions for Mutex Lock and Semaphore Waiting in Packet Processing
I am developing a multi-threaded network application focused on packet processing that involves sender and receiver threads. This application runs on a single-core CPU, which adds complexity to how ...
0
votes
1
answer
59
views
Executing a binary semaphore or mutex for context switching operation in python multiprocessing
I'm trying to automate a sync relation between a win application and a java application.
My criteria is :
start win and jav application
execute command in jav application
wait for response from jav ...
0
votes
1
answer
80
views
How to achieve maximum throughput without using lock-free mechanism? On thread-safety circular queue
I use two mutexes for enqueueTS() and dequeueTS(), so that writer and reader threads can run simultaneously without waiting for each other. However, both enqueueTS() and dequeueTS() can affect member ...
0
votes
1
answer
114
views
How should I initialize pthread mutexes in shared memory, since at program start they can be already initialized?
I'm using shared, robust pthread mutexes to protect some shared memory areas I have in my application. Since my program is managed by a systemd service, it could potentially be restarted, in which ...
0
votes
1
answer
71
views
Fill a matrix in parallel - how to convert `Vec<Arc<Mutex<Vec<_>>>>` to Vec<Vec<_>>`
I'm learning Rust and just finished the Fearless Concurrency chapter in the Rust book, so am trying to fill up the rows of a matrix in parallel.
My matrix is large, so I send a chunk of rows to each ...
0
votes
1
answer
52
views
If the Linux kernel reassigns a PID, can this cause errors/UB when using C pthread mutexes?
If I'm getting it right, is it possible in the Linux pthread C API to use robust mutexes, that can be shared across processes (by placing them in shared memory), and that allows you to acquire the ...
0
votes
1
answer
65
views
Cache deletion and refreshing data race
I'm starting to learn about caching and have thought of the following problem, and really only see one way to solve it but I'm sure I am missing something
Lets image that I have two endpoints, one for ...
-2
votes
1
answer
136
views
What the correct way working with threads with arc mutex? [duplicate]
I have some urls, then i divide it with chunks and iterate them concurrently, saving results in vec using cloning:
pub fn collect_parm_list(url_list: Vec<String>) -> Result<Vec<String&...
-1
votes
4
answers
171
views
Lock based concurrent vector
I am starting with designing thread safe data structure and looking to implement a concurrent vector that hides multi-threading complexity for the user and that offers thread safe clear function (...
0
votes
0
answers
54
views
Why is Linux mutex_waiter struct created on the kernel stack?
I examined the Linux mutex implementation code, where if the lock is held by others, the lock function creates a mutex_waiter struct on the stack (as a local variable) and adds this struct as a node ...
1
vote
1
answer
318
views
Is pthread_mutex_lock() a syscall?
I'm trying to measure the system time and user time for pthread_mutex_lock(), and this is the function I came up:
void measure_mutex_lock_time(double *user_time, double *system_time) {
...
0
votes
1
answer
643
views
Performance in Go: Mutex vs RWMutex
There are two types of mutex in Go: Mutex and RWMutex
Mutex offers func Lock() and func Unlock().
RWMutex offers those functions plus func RLock() and func RUnlock().
From what I understand, we ...
-1
votes
1
answer
69
views
GO Cond - fmt.Println after wg.Done ended up dead lock
Unable to understand this dead lock situation in golang, i have below to go code with pub and sub pattern
package main
import (
"fmt"
"sync"
)
func main() {
cond := ...
1
vote
2
answers
987
views
Need help in preventing multiple crons/scheduler running in golang
I'm working on a Go microservice where I am using robfig/cron package to schedule jobs, initially thought of using time.Ticker() but package made it easier for me.
My question is how to ensure cron ...
1
vote
1
answer
105
views
WebAssembly wait & notify not working across wasi threads
I'm trying to make a thread_join function in WebAssembly by setting a mutex to 1 in the main thread, and then launching a thread. the thread unlocks its mutex before exiting. the main thread can get ...
13
votes
1
answer
273
views
Can the C++ compiler coalesce adjacent mutex locks?
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++;
}
{
...
0
votes
1
answer
163
views
How can I push a newly instantiated mutex into std::vector<std::mutex>? [duplicate]
I can initialize a std::mutex with auto mtx = std::mutex(); but it seems impossible to push one into std::vector<std::mutex>:
both
std::vector<std::mutex> vec;
vec.push_back(std::...
1
vote
2
answers
63
views
Sequence of tasks in Multithreading
I am new to threads and multithreading.(Win socket API)
I am trying to achieve the sequence of tasks in 2 threads with proper synchronization.
no. of threads 2 : Thread_A and Thread_B
Thread_A{
...
4
votes
3
answers
238
views
Can std::recursive_mutex ever cause a deadlock?
I know if I lock std::mutex twice in one thread, it will cause a deadlock.
So, I globally replaced std::mutex with std::recursive_mutex.
Does only using std::recursive_mutex mean I will never ...
0
votes
4
answers
137
views
C++ with Qt5 : lock a common mutex before calling the actual override implementation of a method
I have an abstract class like this :
class Thing
{
public:
Thing();
virtual ~Thing();
static QMutex s_mutex;
virtual void load() = 0;
virtual void translate() = 0;
virtual ...
0
votes
1
answer
20
views
Non-symmetric mutex
I have an unknown number of processes that create independent data, and one function that modifies all existing data. I need to be able to prevent the modification of data when it is being created (or ...
2
votes
1
answer
136
views
How to safely access vector references in C++14
I have a class managing vector data using the singleton pattern.
class DataManager
{
public:
static DataManager& GetInstance() {
static DataManager instance;
return instance;
...
31
votes
1
answer
14k
views
First std::mutex::lock() crashes in application built with latest Visual Studio 2022
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 start ...
5
votes
1
answer
422
views
Mutex poisoning in C++
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?