Questions tagged [multithreading]
Multi-threading related questions including technique, structure, and safety issues.
686 questions
4
votes
2
answers
160
views
Multi processing or multi threading for pywinauto?
I am trying to automate an old GUI tool which requires filling in some data from a CSV and selecting appropriate tree item values based on it. I need to do this in multiple instances of the ...
2
votes
4
answers
203
views
Multithreaded Game Server: Single send() or Many send()s for Game List?
I'm developing a multithreaded game server (C/TCP). I need to send a list of 50-100 available games to a console client.
Option A: Send 50-100 separate messages, using send() for every single ...
1
vote
1
answer
111
views
Handling order Id In OMS system on application level [closed]
Situation: Order Handling in OMS System: In my OMS system, orders are pushed from an online platform with a unique orderId.
Since the orderId is generated by the online platform, I cannot make it auto-...
3
votes
3
answers
695
views
How can single thread execution speed further increase since frequency stagnates?
What are things that newer CPU can do to speed up single thread execution?
multiple registers? (can compilers always benefit from it?)
SIMD? (do compilers use SIMD without code annotation?)
does a ...
1
vote
1
answer
413
views
What does it mean to be "truly" asynchronous?
Reading the Proactor pattern paper, specifically this part:
I/O Completion Ports in Windows NT: The Windows NT operating system implements the Proactor pattern. Various Asynchronous Operations such ...
4
votes
10
answers
5k
views
Can multi-threading improve performance of an IO-bound process?
I am trying to understand the difference between CPU Bound vs IO Bound process. ChatGPT suggested that multi-threading/parallel processing can help a CPU bound process; However, I think that having ...
0
votes
1
answer
261
views
An adaptor layer for Pthread, C11, and C++11 threads compatibility
As my next spare-time project, I'm considering writing a suite of compatibility header and associated library, that eases the transition from Single Unix Specification v4 to v5 and C11/C17 to C2X. C++ ...
0
votes
1
answer
610
views
Global Variables State Management
Background:
I am working in a Java environment using Spring Boot, where I often encounter scenarios where global variable state management is critical, especially within singleton services. I have ...
10
votes
5
answers
4k
views
Writing public libraries: Should I let the consumer of the library enforce thread safety?
I'm writing a .NET library which exposes certain public APIs. Currently, I have not enforced thread safety in my library for following reasons apparent to me:
locks (Monitor.Enter and Monitor.Exit) ...
0
votes
1
answer
150
views
In Java's Fork/Join is the operation for combining results limited to addition?
As I understand it, the join() method merge/composes/combines the results from all subtasks. A simple example I saw was summing the numbers from 1 to N and the subtasks would simply sum a range of ...
0
votes
2
answers
1k
views
What problem does Rust's "atomic reference count" actually solve?
The Rust programming language offers a Arc atomic reference counting generic type for use in multi-threading environment, since Rc is optimized for performance in single-threaded applications, and ...
1
vote
1
answer
173
views
Non blocking algorithm for invalidating and reloading cache in concurrent environment using Redis (with Redisson)
I'm trying to come up with a peace of code that would fetch centralised cache shared across multiple threads/app instances. Callers might come in swarms. The data is a large set, reads during ...
1
vote
2
answers
491
views
How to handle errors of pthreads fundamental lock und unlock functions?
I am writing a little C library for the Raspberry Pi for controlling 433MHz transmitters/receivers. While receiving data the whole application would block, so I decided to put this code into a ...
1
vote
2
answers
369
views
Maintaining locks across abstraction
Over and over I am faced with a similar problem: I have to perform two actions that are mostly unrelated, except that they need to share a mutex lock, at least for a moment. For example:
void action() ...
0
votes
5
answers
1k
views
Can interpreted language be natively multithreaded?
First of all, let me clarify the terms in order to avoid any possible misunderstandings.
Language is considered to be compiled when a program written in it's source code cannot be run directly without ...
1
vote
1
answer
1k
views
Linux poll with a thread pool and multiple events
I am working on a simple client server program in C in which multiple clients will be connected to a single server.
Clients will submit operations/actions to the server and the server will process ...
0
votes
1
answer
1k
views
Comparing synchronization primitives (future, barrier, conditional var) - which one fits the best?
Trying to understand and compare synchronization primitives, like std::future/std::promise, std::barrier and std::conditional_variable - developing an intuition for which one to use when exactly.
I ...
1
vote
4
answers
924
views
How can I keep accurate time in a Windows Forms (WinForms) application?
I am an inexperienced developer fresh out of college. I was handed a Windows Forms Application to work on.
The application previously relied on system time. They wanted me to make it so that we could ...
0
votes
1
answer
128
views
NIC handling multiple packets at once
Can NIC handle(send/receive) multiple packets at once?
For example, 2 asynchronous tasks request 2 different things from a database. Are those 2 requests sent simultaneously by NIC? Also, are the ...
0
votes
3
answers
2k
views
How to combine epoll + multithreading in an HTTP server
I'm building an HTTP server in C using epoll and pthread. The idea is to have an event loop in the main thread monitoring file descriptor and a thread pool to handle computationally-expensive ...
1
vote
2
answers
1k
views
design pattern to avoid deadlock with mutex in golang
What would the appropriate design pattern to avoid deadlock when several functions use the same mutex ?
It is quite easy to forget what method uses the lock and so it happens that you call a function ...
4
votes
2
answers
1k
views
How can a web browser simultaneously run more videos than the number of CPU cores?
I've been learning about threads and processes and I understand that threads allow you to write concurrent code: where executing threads switch very quickly from one to another, giving the impression ...
0
votes
2
answers
4k
views
How to terminate python queue and instruct all consumer-threads to finish their tasks?
I have a multi-threaded application.
There is 1 thread that produces a resource and puts it into a queue and many (not constant amount) consumer-threads that get the resources from the queue.
When ...
1
vote
4
answers
5k
views
Multithreaded processing of single REST requests
Background:
We're providing an API that provides information about all users within a given group. Our API is a high level facade over another low-level REST API.
To gather those information we first ...
4
votes
3
answers
2k
views
N threads enter, one and only one should do extra processing that others wait for
My task is, I think, pretty interesting, if a bit unusual. Any number of threads can call function f(). They add some data to a buffer and begin waiting (the function is blocking). Eventually some ...
20
votes
8
answers
6k
views
What causes unpredictability when doing multi threading
Multi threading could cause a racing condition if two threads are accessing the same memory slot, but why is that? From a HW point of view, if the two cores are designed the same, internal pipelines ...
0
votes
2
answers
2k
views
Low-Latency Data Sharing Between Threads in C++: Options and Considerations
What are the most efficient and low-latency approaches for sharing data between threads in a C++ system, and why? My primary concern is minimizing latency and maximizing performance, as I have two ...
7
votes
1
answer
552
views
Can functional programming languages have deadlock conditions?
I am reading through "Clean Architecture: A Craftsman's Guide to Software Structure and Design" and it says that:
All race conditions, deadlock conditions, and concurrent update problems are ...
0
votes
1
answer
171
views
Difference between outcome of using mutex/spinlock/semaphore in this deadlock situation?
I'm not sure if my answers to the following exercise is correct:
Suppose the program is run with two threads. Further suppose that the
following sequence of events occurs:
Time Thread 0 ...
0
votes
1
answer
330
views
Reducing contention/locking in a job system involving read/write dependencies?
I have a job system that has two different types of dependencies per-job:
Jobs can rely on other jobs to be completed first, but this is optional
Jobs have read/write dependencies (shared/exclusive) ...
0
votes
0
answers
1k
views
How does Spring boot and Postgres handle the concurrent updates?
I want to understand how does Spring Boot and Postgresql DB handle the concurrent requests for updating a value in DB. Consider this example of facebook likes, if there are multiple instances of ...
3
votes
3
answers
5k
views
When should one utilize Atomic Operations?
I have never used atomic operations, and remain largely ignorant of how to utilize them. And yet, I often come across objects like this when peering into Qt's backend:
https://doc.qt.io/qt-6/...
1
vote
0
answers
299
views
If you run a function in a different thread, but you wait for it to finish in your main thread, is that function asynchronous?
Backstory
Probably a stupid question, but I just have a sneaking suspicion that "asynchronous" is the wrong terminology to us for naming my template function here:
template <class T>
...
0
votes
1
answer
350
views
Design of A Multithreaded Simulator
When designing my simulator, I have gotten stuck on 2 main design choices.
The simulator can be described as having X number of nodes (between 50 - 2000) that each need to independently do some ...
-1
votes
2
answers
124
views
Multi-threaded design for continuous messages analysis
Since I don't have much knowledge of multi-threaded design and English is not my native language, I don't know how to exactly describe my problem.
Let's say I have a mini-program in school, which has ...
0
votes
1
answer
279
views
Best way to accept a lot of user input from command line
I have a program that accepts computer names and then will perform CIM session tasks. The computer names are passed in from the user input and separated by "," (ex: program.exe -computers ...
33
votes
7
answers
8k
views
Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?
Sometimes computers stutter a bit when they're working hard, to the point where the mouse location freezes for a fraction of a second, or stutters intermittently for a few seconds. This sometimes ...
-1
votes
2
answers
295
views
Do I really need TaskManager class? [duplicate]
Background:
I'm coding an app, the core idea is simple - I can choose a 'Task' (consists of name, code to perform aka Runnable, progress) through GUI, start it, stop it, start all 'Task's and stop all ...
0
votes
2
answers
395
views
Accessing Hardware-based resources from multiple worker threads
I have a technical application that interacts with different hardware components: measurement devices, sensors, custom hardware. These use dedicated interfaces like USB, serial ports, TCP/IP ...
1
vote
1
answer
920
views
Shared mutable object in Multithreading
I have a class like this. (My actual class is different. I am using this to explain the problem). This class instance is shared between 2 threads.
However those 2 threads (thread1 and thread2), call ...
-2
votes
1
answer
217
views
What is the benefit of equipping a computer or smartphone with multiple CPU cores that differ in clock speed? [closed]
I've bought a samsung galaxy s21 ultra about a year ago. Today i was looking at the specs again and i noticed that the Samsung Exynos 2100 processor consists out of 1 single CPU core of 2.9 GHz, three ...
0
votes
0
answers
88
views
Do datacenters have conditions that might throttle component clock speed (either intentionally or automatically)?
Here is the question.
On a 2.2 GHz processor with 6 physical threads and 6 hyperthreads, I see performance on the order of 3-10s for a particular job involving OpenCV.
I do not specify that the ...
-1
votes
2
answers
1k
views
What happens when one thread is waiting to be executed while another is waiting for input?
Suppose I have two threads, A and B. A is waiting for input, while B is waiting to be executed. All other CPU cores are busy with CPU-bound tasks.
What will happen to A?
4
votes
1
answer
2k
views
One producer - multiple consumers queue, best way to guard against rare duplicates?
I have a classical one producer - multiple consumers queue, each item can be processed independently. On rare occasions (<1%) there can be multiple queue items related to the same object the ...
0
votes
3
answers
628
views
Lockfree customer producer problem
We have following class:
class ProcessStore
{
ConcurrentDictionary<int, MyDisposableClass> _processes = new();
bool _disposed;
void Store(int Id)
{
if(_disposed) { throw; }
...
3
votes
1
answer
189
views
Design for deduplicating concurrent tasks in flight simultaneously
I have 1-20 agents that issue requests over time with roughly ~50 in total in flight at any given time. Many of these requests are identical. The tasks are idempotent, but if two identical requests ...
0
votes
1
answer
2k
views
Run lambda inside a separate thread with a member variable caught by reference
So, I have the following two functions in THE SAME class:
void start()
{
...
m_pRunnable = createRunnable(
[spDiskManager = m_spDiskManager,
path = m_path,
&success =...
0
votes
1
answer
3k
views
C# Kafka Consumer design
I have a C#-based system that works relatively well. It reads data from kafka, processes the data and then writes it out to MSSQL.
The kafka topic has been partitioned into 10 partitions - and after 2 ...
10
votes
8
answers
4k
views
Why is there a shift towards asynchronous and event driven programming?
My question will be mostly about Linux and contemporary X86 hardware.
Clarifying the terms
async event based programming: spawning fixed amount of threads and using some user space scheduling ...
0
votes
3
answers
233
views
Critical section with two different "rights of way" [closed]
In C#, how do I handle critical section with two different "rights of way"?
Theoretical use case: imagine a swimming pool (the resource). Many individual swimmers (worker threads A, B, C, ...