Questions tagged [multithreading]

Multi-threading related questions including technique, structure, and safety issues.

Filter by
Sorted by
Tagged with
-1 votes
2 answers
82 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 ...
4 votes
1 answer
815 views

Reading and conditionally updating N rows, where N > 100,000 for DNA Sequence processing

I have a proof of concept application that uses Azure tables to associate DNA sequences to "something". Table 1 is the master table. It uniquely lists every DNA sequence. The PK is a load ...
1 vote
2 answers
1k views

Multiple API calls potentially spawning multiple Websockets - Threading vs Async

I am designing a program with the flow as outlined below. Note, these are all network calls, there is no system I/O (hard drive). Initially, multiple independent API calls need to happen - they don'...
1 vote
2 answers
201 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; } ...
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 ...
0 votes
2 answers
202 views

Worker pool running tasks of the same kind serially

I would like to run tasks in parallel. At this time, I am using a very simple worker pool using a single concurrent queue shared by all the threads. Every task has a non unique "tag" (an integer in ...
0 votes
2 answers
114 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 votes
2 answers
111 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 ...
2 votes
1 answer
3k views

Common Qt Producer/Consumer Example: What is the point of multithreading here?

While trying to figure out how to implement a Producer/Consumer Queue in Qt, I stumpled upon several SO answers, blogs and sites linking to this site: You're doing it wrong... I got the point of this ...
-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 ...
1 vote
1 answer
111 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 ...
1 vote
1 answer
246 views

What are the limitations of WinSock2 sockets within threads?

I've run into some strange behavior on an application I'm developing in C using the windows API. Im trying to implement a closed connection server-client interface. However, for whatever reason ...
0 votes
0 answers
30 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
154 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
55 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
115 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
143 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 ...
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 ...
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
1 answer
233 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
253 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 ...
0 votes
3 answers
169 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. ...
14 votes
6 answers
3k views

How to prevent two users from registering at the same instant with same username?

We cannot serialize registrations as there are millions of users registering at the same time. Parallel registrations need to happen. Let's say the database doesn't contain username 'user1'. When two ...
1 vote
1 answer
125 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 ...
0 votes
1 answer
560 views

Primes and multi-threading

I use to compute primes using linear code which took a long time. As I've an 8 cores processor I thought about multi-threading. At first I use to put a huge number of int in a vector then share 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
89 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
175 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
241 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 ...
2 votes
3 answers
2k views

Multi cores/CPUs with locks

I'm not sure how the locks will work with multi processors/cores, I'm going to use shared memory in my application or FIFO, what worries me is the locks, I have a server with 2-CPU, how the lock will ...
4 votes
4 answers
775 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 ...
29 votes
3 answers
55k views

UML Diagrams of Multi-Threaded Applications

For single-threaded applications I like to use class diagrams to get an overview of the architecture of that application. This type of diagram, however, hasn’t been very helpful when trying to ...
0 votes
1 answer
105 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
5 answers
724 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
153 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 ...
-4 votes
1 answer
92 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
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(~...
21 votes
3 answers
14k views

Do compilers utilize multithreading for faster compile times?

If I remember my compilers course correctly, the typical compiler has the following simplified outline: A lexical analyzer scans (or calls some scanning function on) the source code character-by-...
0 votes
1 answer
125 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 ...
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 ...
7 votes
4 answers
3k views

Is the meaning of `const` still thread-safe in C++11?

I recently came across Herb Sutter's video from about how the meaning of const and mutable has changed in C++11 to mean bitwise const (and thread-safe, as a consequence) instead of the traditional ...
1 vote
1 answer
184 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 ...
1 vote
2 answers
439 views

RxJava and race conditions

I have seen some RxJava projects using multithreading with .subscribeOn(Schedulers.io()), and their .subscribe(() -> {...}) code is manipulating some data structures that are also processed by ...
8 votes
2 answers
5k views

How would you design a “multithreaded” LRU cache using C++ (unordered_map and Linkedlist)?

Please note that this is about a thread-safe LRU cache (not simply a LRU cache as specified in https://leetcode.com/problems/lru-cache/description/). It isn't a duplicate of LRU cache design question ...
-1 votes
1 answer
64 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
68 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 ...
37 votes
3 answers
28k views

Can someone explain in simple terms what is the disruptor pattern?

I would like if you could explain to me in a simple way how does the disruptor patter work. This concept has been elusive to me as of know. Perhaps with your help I could comprehend it.
4 votes
4 answers
7k views

Generate a random color for every user and keep track of created colors. Every color MUST be different

In my app every user that connects to the server needs to get a random distinct color and I have to keep track of them. About 20 to 30 will be connected in the same time. When a user disconnects, his ...

1
2 3 4 5
14