Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
3 votes
1 answer
146 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
50 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
86 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
276 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
456 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/...
  • 3,399
0 votes
0 answers
59 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> ...
  • 3,399
0 votes
1 answer
95 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
87 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
190 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 ...
  • 11
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
124 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 ...
  • 33
0 votes
2 answers
141 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 ...
  • 119
1 vote
1 answer
158 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
32 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 ...
  • 131
-2 votes
1 answer
162 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 ...
  • 123
0 votes
0 answers
58 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 ...
  • 109
-1 votes
2 answers
230 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?
  • 2,031
4 votes
1 answer
186 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
239 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; } ...
  • 363
2 votes
1 answer
91 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
621 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
562 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
2k 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
172 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, ...
  • 119
1 vote
1 answer
156 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
3k 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 ...
  • 335
0 votes
0 answers
124 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
274 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
285 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
1k 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
172 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. ...
  • 117
-4 votes
1 answer
116 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 ...
  • 117
0 votes
1 answer
240 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 ...
  • 113
0 votes
1 answer
117 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
1k 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
269 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
225 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
2k 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 ...
  • 181
0 votes
3 answers
102 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 ...
  • 115
-1 votes
1 answer
83 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
110 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 ...
  • 101
0 votes
2 answers
461 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 ...
  • 137
1 vote
3 answers
251 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
89 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 ...
  • 11
5 votes
2 answers
304 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
120 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
587 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
241 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
271 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
67 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(...
  • 103

1
2 3 4 5
14