Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
-1 votes
2 answers
74 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 ...
user avatar
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 ...
user avatar
-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 ...
user avatar
  • 35
0 votes
2 answers
113 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 ...
user avatar
  • 119
1 vote
1 answer
110 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 ...
user avatar
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 ...
user avatar
  • 131
-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 ...
user avatar
  • 123
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 ...
user avatar
  • 109
-1 votes
2 answers
113 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?
user avatar
  • 2,021
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 ...
user avatar
1 vote
2 answers
200 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; } ...
user avatar
  • 353
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 ...
user avatar
0 votes
1 answer
214 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 =...
user avatar
0 votes
1 answer
232 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 ...
user avatar
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 ...
user avatar
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, ...
user avatar
  • 119
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. ...
user avatar
  • 101
1 vote
1 answer
124 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 ...
user avatar
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 ...
user avatar
  • 335
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 ...
user avatar
1 vote
2 answers
174 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 ...
user avatar
3 votes
2 answers
239 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 ...
user avatar
4 votes
4 answers
759 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 ...
user avatar
0 votes
1 answer
103 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. ...
user avatar
  • 117
-4 votes
1 answer
90 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 ...
user avatar
  • 117
0 votes
1 answer
152 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 ...
user avatar
  • 103
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(~...
user avatar
4 votes
5 answers
710 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 ...
user avatar
0 votes
1 answer
122 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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 181
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 ...
user avatar
  • 115
-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 ...
user avatar
0 votes
1 answer
66 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 ...
user avatar
  • 101
0 votes
2 answers
362 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 ...
user avatar
  • 37
1 vote
3 answers
224 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 ...
user avatar
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 ...
user avatar
  • 11
5 votes
2 answers
265 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 ...
user avatar
  • 189
-1 votes
1 answer
113 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 ...
user avatar
4 votes
2 answers
476 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 ...
user avatar
2 votes
1 answer
180 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 ...
user avatar
0 votes
2 answers
257 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 ...
user avatar
-3 votes
1 answer
66 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(...
user avatar
  • 103
4 votes
4 answers
710 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 ...
user avatar
  • 5,271
-2 votes
1 answer
129 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 ...
user avatar
  • 5,271
2 votes
0 answers
98 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 ...
user avatar
-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 ...
user avatar
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, ...
user avatar
  • 31
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 ...
user avatar
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 ...
user avatar

1
2 3 4 5
14