141,057 questions
2
votes
0
answers
92
views
Memory leak in JNI with AttachCurrentThread() and DetachCurrentThread()
I have a Java application that calls a native function. That native function has a loop and in each iteration launches 10 threads and waits for them to complete. Each thread just does a number of ...
0
votes
1
answer
90
views
Deferred cancellation in C [duplicate]
I am learning on how threads can be cancelled. Asynchronous cancellation can cancel the thread at any given point in time, but what I have learned about deferred cancellation is that it can only be ...
0
votes
1
answer
100
views
Get System.Timers.Timer to fire on a WPF Window's thread using the Timer's SynchronizingObject
I tried setting the SynchronizingObject like this:
timer.SynchronizingObject = this;//The Window
but VS told me I need an explicit cast. So I did that and the error went away.
timer....
0
votes
3
answers
101
views
Threading in Rust with mutable objects
I'm quite new to rust and want to do two function in parallel.
shoot(&fleet_a, &mut fleet_b)
shoot(&fleet_b, &mut fleet_a)
since they only take information from one and modify some ...
1
vote
1
answer
53
views
Actix-web + Tokio: Server hangs when using tokio::spawn with Arc<Mutex> loop
I am facing an issue where my Actix-web server starts correctly, but the moment I hit the /upload_chunk endpoint from my frontend, the request hangs forever.
After some debugging, I found that the ...
0
votes
1
answer
81
views
I have two simple Python functions with time.sleep and reading data so I/O-bound but I don't get expected behavior from threading and asyncio
Previously I had a question on an example of multiprocessing which you can see in the following link
I used a 2 workers pool to split a sum in a function with Python multiprocessing but the timing ...
2
votes
1
answer
140
views
How is a non-parallelized for loop inside an OpenMP parallel section executed?
Consider the following code:
#pragma omp parallel
for (int run = 0; run < 10; run++)
{
std::vector<int> out;
#pragma omp for
for (int i = 0; i < 1'000'000; i++)
{
...
}
}
...
Advice
1
vote
13
replies
121
views
C# - lock multiple methods or entire class to single thread execution
I am trying to ensure that methods in my class can only be called by a single thread.
So far tried to use ReaderWriterLockSlim to achieve this effect but this can cause potential issues if it is not ...
Best practices
0
votes
3
replies
66
views
Is there anyway to get physical disk Idle time without 1 second wait needed for PerformanceCounter.NextValue function?
I trying to develop user-friendly program that do not block physical disk with 100% usage (so even entering My Computer takes around 10 seconds).
My program calculate hash for many (180k) small files ...
0
votes
1
answer
50
views
VSPackage fibers stack tracing
I am trying to display the stack traces of RTOS fibers running in a C++ solution in VS2022. Since upgrading to Windows 11 there seems to be a problem in the implementation. The existing approach, ...
0
votes
2
answers
134
views
compare_exchange_strong failed to update the expected value
I am trying to implement a lock-free multiple-producer-single-consumer ring buffer in C++. Here is the full definition and the test code.
#include <iostream>
#include <memory>
#include <...
5
votes
2
answers
195
views
Is there a difference between the C# Volatile.ReadBarrier vs Volatile.Read?
In the released .NET 10 there is a new method added to the Volatile class with the name ReadBarrier().
And I don't know whether from the compilers perspective there is a difference if I do a read with ...
1
vote
1
answer
137
views
Why does my multithreading/pointers code print random values?
My code should print the numbers given as command line arguments. Instead it prints random-looking values.
What is going on and how can I fix it?
#include <stdio.h>
#include <pthread.h>
#...
1
vote
0
answers
62
views
C# Multithreading Issue with Simultaneous Smart Card Printing on Multiple Evolis Primacy 2 Printers
I'm developing a C# application that needs to handle simultaneous printing on 4 Evolis Primacy 2 printers with Elyctis encoders. Each printer must write to card chips and print on cards completely ...
4
votes
1
answer
99
views
Java ExecutorService detect asap thread fail
I have to run x asynchronous threads , which can last several minutes each.
They ALL have to terminate properly without exceptions.
If one fails I have to stop them all immediately and not wait ...
2
votes
1
answer
65
views
Opening a pop-up window when error from a worker running in Qthread occurs completely freezes the program
I was trying to create a little Python program with a GUI using Pyside6. I ran into a problem when creating a thread for a worker to do a task (check files with a certain condition and then copy them ...
1
vote
1
answer
196
views
How to benchmark atomic<int> vs atomic<size_t>?
I have a bounded queue with small size that definitely fit in int. So I want to use atomic<int> instead of atomic<size_t> for indexing/counter, since int is smaller it should be faster.
...
0
votes
1
answer
149
views
Syncronizing files between threads
Assume 2 threads, t1 and t2, mutex m and file f running on a RPi.
t1 waits at m, creates a file f with some content, close f and verify that f exists. Finally m is relased and t1 does a short delay to ...
2
votes
1
answer
53
views
How to workaround slf4j reading disk on main thread in Android?
I do have the following line in my Android app:
private Logger logger = LoggerFactory.getLogger(getClass().getSimpleName());
When testing for threads access in strict mode i found the following issue ...
0
votes
1
answer
57
views
How to set up multi-thread logging to different loggers using QueueListener and QueueHandler
I have a Python application that runs multiple tasks in parallel using ThreadPoolExecutor. I want all threads to log safely without race conditions. I also need two loggers:
Console logger (prints ...
0
votes
1
answer
102
views
Pyspark- Multithreading in Python
I have a user case like this. I have a list of many queries. I am running multi-threading with pyspark with each thread submitting some sql.
There are some queries that report success but the final ...
0
votes
1
answer
328
views
Can external IO operations be considered as if seq_cst operations in the reasoning of multithreaded programs?
Consider this example:
// thread A:
start_transaction();
update_mysql();
commit_transaction(); // remove "key" from mysql tables
remove_redis_cache("key");
// thread B:
std::...
0
votes
2
answers
62
views
Calculate byte positions to split ndjson files into chunks
Below is the code extracted from this repo:
import os.path, io
filename = ""
n_chunks = 12 # Number of processes to use -- will split the file up into this many pieces
def ...
-1
votes
0
answers
139
views
Java Multithread EventHandling
I'm trying to write an audio player in Java/JavaFX and want to make a playlist play songs automatically. I have a button that triggers a new thread, and everything works fine so far.. but when the ...
0
votes
1
answer
94
views
Python gets stuck in an infinite loop restarting multiprocessing pool workers on error in initilization routine
I am trying to setup a multiprocessing Python task on Windows 10, Python 3.13. I have "main.py" module, containing the main entry, "orchestration.py" module with worker ...
6
votes
1
answer
343
views
Is it possible to build a mutex from C++20 std::atomic without spinning to avoid use-after-free when deleting?
Before I get to my main question, I'm assuming that std::mutex::unlock() stops touching this as soon as it puts the mutex in a state where another thread might lock it - even though the call to unlock(...
2
votes
2
answers
209
views
Is it possible/how to let parent class thread invoke function in child class that overrides parent function?
I am trying to implement a Parent and Child class. The Parent class would start a thread and run a routine function. The Child class would override the routine function if needed.This seems perfectly ...
12
votes
1
answer
733
views
How can I set up Thread-Local Storage (TLS) callbacks on Windows without CRT?
I'm trying to register a Thread-Local Storage (TLS) callback in a Windows application without using the C runtime (CRT).
Compiler: MSVC 14.44.35207 (Visual Studio 2022)
Target: x64
OS: Windows 11
I ...
0
votes
0
answers
42
views
How to achieve complete read/write thread separation for BoringSSL using BIO APIs
I'm integrating BoringSSL into my networking library for secure communication. I've observed that both SSL_read() and SSL_write() operations can potentially trigger both read and write activities on ...
5
votes
0
answers
230
views
Why does this data race have some consistent invariants with writers updating one of three atomic<int> variables?
I have the following program. The relevant info is:
There are 3 variables atomic<int> x,y,z accessed by all threads.
3 writer threads: Each thread read all 3 values x,y,z, and update exactly 1 ...
-1
votes
0
answers
200
views
+50
Do the RMW operations on `cnt` still not avoid an inconsistent status for this multiple-producer single-consumer implementation?
Looking at this implementation of multiple-producer single-consumer, which was the implementation in Rust's standard library; however, its memory order model is derived from C++. So, it should be ...
0
votes
1
answer
164
views
Does an implementation that reorders evaluation in a single thread violate [intro.execution] p8?
[intro.execution] p8 says:
Given any two evaluations A and B, if A is sequenced before B (or, equivalently, B is sequenced after A), then the execution of A shall precede the execution of B.
...
2
votes
2
answers
170
views
Java Thread interrupt non deterministic behaviour
I have this piece of code in Java and I tried it out on Java 21 (Eclipse Temurin and GraalVM)
public static void main(String[] args) {
Thread.currentThread().interrupt();
long start = ...
2
votes
1
answer
85
views
How does Linux Perf manage hardware counters when profiling a multithreaded process?
I am trying to understand how Linux Perf manages hardware counters when profiling a multithreaded process.
According to the documentation, the perf_event_open syscall can be used in two ways:
To ...
1
vote
1
answer
137
views
is jax really incompatible with python multiprocesses? [closed]
I have a simple app with a main controller process, and a child process that handles API calls. They communicate using Python queues.
The app looks (something) like this:
import multiprocessing as mp
...
4
votes
1
answer
115
views
Understanding usage of withFileBlocking with named pipes
The following program
assumes that /path/to/mypipe is a named pipe, e.g. created via mkfifo /path/to/mypipe, with no readers/writers waiting yet,
runs two threads, of which
the main thread keeps ...
3
votes
2
answers
163
views
Why std::atomic::store can be moved ahead of its argument's initialization in runtime?
I'm reading this: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3292r0.html
Here's code sample the question is about:
int dummy;
std::atomic<int *> ptr_to_int_1{&dummy};
std::...
0
votes
0
answers
161
views
Is I2C device interface thread-safe on Linux?
I have a single board computer with a I2C GPIO expander device, listed as /dev/i2c-0. In my multithreaded program I open() this character device and read/write to it on separate threads using ...
0
votes
0
answers
127
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 ...
0
votes
1
answer
72
views
What’s the difference between concurrency and parallelism on a single CPU core with 2 hardware threads?
Let's say I have a CPU with 1 core and 2 hardware threads (for example, with Intel Hyper-Threading or AMD SMT).
From what I understand, that means the core can run two software threads "at once&...
0
votes
1
answer
65
views
Is data synchronization necessary on single-threaded systems?
This question stems from a technical interview where I was asking candidate about multithreading, and the differences between "true multithreading" via multiple hardware cores and/or ...
1
vote
2
answers
63
views
Intermittent segmentation fault in OpenSSL SHA1_Update after days of operation in multi-threaded C program
----Problem Summary----
I'm experiencing intermittent segmentation faults in a multi-threaded C program that heavily uses OpenSSL's libcrypto for cryptographic operations. The crash occurs in ...
3
votes
1
answer
142
views
Even after clicking on the terminal screen, it doesn't print "Left pressed", how do i fix this?
I want it to print that whenever you click on the terminal screen.
I'm using win32 API in C programming btw, and here is the full code below:
#include <stdio.h>
#include <windows.h>
#...
0
votes
0
answers
454
views
How to enable free-threading in Python 3.14 with Python install manager?
Python has officially introduce Python install manager and free-threading feature in 3.14, but I cannot find out how to enable free-threading feature with Python install manager. Is there a way to ...
4
votes
1
answer
218
views
How do I interrupt a pybind11 exec call?
I am trying to make an application using python code and C++, but I need some kind of protection against infinite loops or too long executions. I tried following some threads and seeing how other ...
2
votes
1
answer
105
views
Why OpenCV does not utilize multithreading for acceleration?
My system and OpenCV version information, source code, and runtime results are as follows:
From this, it appears that multithreading is not functioning.
~$ mamba list | grep opencv
libopencv ...
2
votes
0
answers
92
views
Python app multithread with pyQT5 delivered as .exe using pyinstaller is crashing after 40-50 minutes
I am developing a multithread application using the library pyQt5. There are many threads activated in order to plot in the GUI some data extracted from many devices (one thread <-> one device). ...
2
votes
1
answer
67
views
Cannot start a ThreadPoolExecutor inside a threading.Thread function
In this example, Tkinter GUI starts ThreadPoolExecutor. But ThreadPoolExecutor is inside a threading.Thread function. The thread function says it's finished
before ThreadPoolExecutor has started ... ...
7
votes
1
answer
107
views
Can a channel's Drop omit Acquire ordering, as in the Rust Atomics and Locks book?
In Rust Atomics and Locks chapter 5 (available online for free), this example implementation of a one-time channel is presented:
pub struct Channel<T> {
pub message: UnsafeCell<...
2
votes
0
answers
192
views
Is the Windows Audio Session API thread safe?
Is the Windows Audio Session API (WASAPI) thread safe? Is it okay to call IAudioClient::Start from one thread and then call IAudioClient::GetCurrentPadding and IAudioRenderClient::GetBuffer from a ...