Questions tagged [multithreading]
Multi-threading related questions including technique, structure, and safety issues.
675
questions
1
vote
2
answers
165
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
399
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
208
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
164
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
218
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
49
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
479
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
283
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
730
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
669
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 ...
0
votes
1
answer
2k
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
454
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
5k
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
433
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
375
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
100
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
209
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
691
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
2
answers
2k
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
174
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
178
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
89
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
229
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
7k
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
208
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
266
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
392
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
172
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
61
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
811
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
516
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
423
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; }
...
2
votes
1
answer
122
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
1k
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
1k
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
3k
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
181
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, ...
2
votes
1
answer
327
views
Make multiple data structures thread safe without multiple mutexes
In my application, I have a class which I call a "Signal" (Think Qt signals if you are familiar with that) that represents a one-to-many connection. Objects can register handlers to the ...
19
votes
3
answers
4k
views
How do you test and demonstrate that you have properly prevented a race condition? [duplicate]
Suppose I'm building a web application using Django. Some of the views need to touch multiple database tables or rows, and there is some kind of state consistency that I need to ensure among the ...
0
votes
0
answers
243
views
Multi-threading optimization in-depth
A time ago I participated in an interview process where I was tasked with a simple requirement. I created the best solution I could, using some lock-free implementation.
I didn't pass the code ...
1
vote
2
answers
660
views
Event ordering/ race condition
Here's a scenario I need help with.
Say you have a dating app (distributed, multiple instances), that has a table likes
| id | user_id | liked_id |notification_sent|
If User A likes User B
Insert ...
4
votes
2
answers
402
views
Does creating one thread per event subscriber scale well?
I'm working on an application implemented in different microservices, which uses a message broker (event bus) to consume events (simple pub/sub).
As for now, in a given microservice, we are spawning 1 ...
4
votes
4
answers
2k
views
What will you do if multiple users access your application at the same time?
I'm an experienced Software Engineer but very weak in concurrency because of no prior experience in that. I've been interviewing with several companies in which I was asked similar kind of questions ...
0
votes
1
answer
321
views
Does it make sense to spawn request driven jobs in a thread or process?
I've developed a large application that performs jobs, such that it receives input x and outputs y. For this application, speed is the top priority. The application is capable of running concurrently. ...
-4
votes
1
answer
256
views
Does native async implementation in languages like Python and C# Solve the "Free Lunch is Over" problem? [closed]
A while ago Herb Sutter wrote The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software which I basically interpret to mean that, in order to improve performance, software engineers ...
0
votes
1
answer
495
views
Asynchronous Server in C++
We are looking to develop an asynchronous server in C++. We are coming from C#, which has built-in support for async-await networking. However, with C++ it appears as if it is basically mandatory to ...
0
votes
1
answer
121
views
designing high throughout system for storing hundred thousands incoming records per second in SQL server database
In our company we have a requirement where we would like to store hundred thousands incoming records per seconds. we currently a pub-sub model for processing many records(100/sec) from many system(~...
4
votes
5
answers
2k
views
How can you ensure order of execution in concurrent tasks?
Here is what I am specifically doing:
I have a thread-safe queue
One 'write' thread constantly writes to the queue with data that comes from another service
Multiple 'read' threads take from the ...
0
votes
1
answer
565
views
Is Epoll/Multiplexing suitable to make network requests instead of "listen to" incoming requests?
I'm studying asynchronous IO, concurrent models for IO and how things works on windows, linux and most used web frameworks.
I'm struggling on understanding why single-threaded event loops like the one ...
1
vote
1
answer
360
views
java threading model for scale up
I need some advice on the scale-up issue. we have a java application currently it works as below
the current system is using the Thread Per Request Model.
each client connection (long-running and ...