Questions tagged [multithreading]
Multi-threading related questions including technique, structure, and safety issues.
655
questions
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
109
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
110
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
105
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 ...
0
votes
0
answers
29
views
Multi thread / instances nodeJs application but synchronous event system
I request your help as I am facing a really hard architecture problem:
I need to build a stateless horizontally scalable nodeJs backend capable of processing some events data synchronously.
1 the data
...
-2
votes
1
answer
151
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
54
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 ...
0
votes
2
answers
104
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
139
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 ...
1
vote
2
answers
197
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
87
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
145
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
188
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
1k
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
168
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, ...
0
votes
0
answers
21
views
Controling one stream pipeline (out of two synchronous stream) based on time
[ I am not a SE so my terminologies might be absurd ]
Background
I have two stream: a and b.
Stream b comes to the processing pipeline and after some transformation gets into the database directly.
...
1
vote
1
answer
122
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 ...
18
votes
3
answers
2k
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
83
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
152
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 ...
3
votes
2
answers
235
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
707
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
94
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
84
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
146
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
103
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
647
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
0
answers
188
views
Multithreading vs Asynchronous game loop for multiplayer online game?
I'm trying to create a turn based multiplayer online game where players can be grouped in a room/lobby and play (similar to Ludo but number of players can be more than 4). There can be multiple such ...
0
votes
1
answer
103
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
175
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 ...
7
votes
2
answers
1k
views
What is a "lock ordering inversion"?
I am looking into Eric Lippert's answer to this Stack Overflow question.
In his answer, he uses the phrase "lock ordering inversions" in regard to deadlocks. I've searched the web and have ...
0
votes
3
answers
99
views
Is it better (or preferred) to initialize allocate and free structures used by a thread, "inside the thread"
Let's say we are building a threaded program in C, for example a message queue system where a thread is spawned to manage one end of the queue, and (re)connect sockets.
This can roughly be set up in ...
-1
votes
1
answer
63
views
How should a client handle receiving data from a seperate thread?
There are plenty of tutorials on the internet on how to build a server that handles its clients through the creation of seperate threads, but there is no tutorials (at least I couldn't find any) on ...
0
votes
1
answer
63
views
Is background long running thread a good choice for disk IO?
I am building a storage engine software that allows concurrent data writing, now I have two different choices here:
Method 1. Background Long-Running Thread
Multiple user threads write to their own ...
0
votes
2
answers
346
views
Approaches of splitting the same type of work among multiple threads in C++
I have a reinforcement learning project.
For this I created a vectorized environment in C++, which is a handler for multiple instances of a simple game.
It is highly parallelizable. Each worker can ...
1
vote
3
answers
217
views
Do multiple software-threads on a single hardware-thread system execute sequentially?
I understand that if a system consists of multiple hardware-threads the scheduler
assigns software-threads to hardware-threads.
However, hypothetically, let's imagine a system that does only consist ...
0
votes
1
answer
69
views
Thread-Safety with Enumerable collections and copies
Imagine I have an interface IHeapObject:
interface IHeapObject
{
string Id {get;}
SomeEnum Type {get;}
}
and it's implementation HeapObject:
class HeapObject : IHeapObject
{
public string ...
5
votes
2
answers
261
views
"Threads should only block on one thing" - is this a common best practice?
Context:
Recently I was discussing the design of a small programme with a new team member (I am the product manager). The programme is essentially a protocol converter that reads data from a number of ...
-1
votes
1
answer
112
views
How do social media platforms stay up-to-date with messages and posts? [closed]
This is a question I have always wondered
Is it as simple as repetitive pinging of a server in a seperate thread or is it more complicated than that?
I am only talking about the app version not the ...
4
votes
2
answers
455
views
Hexagonal/Clean Architecture - threads, locks, synchronization
All the examples across the internet try to pretend that every application is run on a single thread. There is no problem with synchronization, multithreading etc. Uncle Bob, in his "Clean ...
2
votes
1
answer
164
views
In an MVC-patterned app, how should one build the interface between model and user interface layers to work nicely with threading?
I am wondering about this. This is a sort of follow-up to my last question here:
In the MVC pattern, what has the responsibility for creating the view?
because now I've run into the question of how to ...
0
votes
2
answers
254
views
My aproach to lockless concurrency
this is a highly theoretical question about my parallelization approach.
First of all, I want to inform everybody that I do not claim that I am the 'inventor' of that approach but I couldn't find any ...
-3
votes
1
answer
65
views
Will this time duration measurement in two threads give correct result?
A program I'm developing has two threads running similar but different task:
thread1:
timer1.start()
writeToExternalDB1(consumedData)
timer1.end()
thread2:
timer2.start()
writeToExternalDB2(...
4
votes
4
answers
660
views
How to understand the first and second readers-writers problems?
Computer Systems: a Programmer's Perspective says
The readers-writers problem has several variations, each based on the priorities of readers and writers.
The first readers-writers problem, which ...
-2
votes
1
answer
121
views
How should functions that keep state across multiple invocations be made safe?
In Computer Systems: a Programmer's Perspective,
12.7.1 Thread Safety
When we program with threads, we must be careful to write functions
that have a property called thread safety. A function is said ...
2
votes
0
answers
97
views
Why does the Java CompletableFuture API uses long + TimeUnit instead of Duration?
Java 9 introduced many new methods in the CompletableFuture API that support execution timeouts.
For example:
public CompletableFuture<T> orTimeout(long timeout, TimeUnit unit);
public ...
-1
votes
1
answer
100
views
How to subscribe to collection edits happening in a different thread?
I'll be using C# for my example since this is what I am using, but the problem is sort of generic.
My app code takes a collection of Foos (externally populated and edited) to do some processing, and ...
2
votes
1
answer
91
views
Effective thread usage under blocking scenario
I have the following scenario:
I am listening file requests and when one arrives, I am starting download task in a new thread. After download task ends, a process task starts but this is important, ...
1
vote
1
answer
74
views
Multi threading a database driven service
First some background on the problem, we have a windows service (C Sharp) that receives new messages and processes them.It is database driven so it checks a table for unprocessed records, processes ...
59
votes
10
answers
23k
views
Does it ever make sense to use more concurrent processes than processor cores?
I've got some process in Go. Here's an example counting lines in text, though the question is meant to be far more general than this particular example:
func lineCount(s string) int {
count := 0
...