Skip to main content

Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
-4 votes
0 answers
19 views

How chromium Site Isolation and process allocation works for Iframe? [closed]

I was with working with a website it contains 6-10 Iframes, Each Iframe contains a web app so obviously there are high chances of that my website get slowed down. So to fix this I tried to understand ...
Karthi Fair Hawn's user avatar
0 votes
0 answers
116 views

Global Variables State Management

Background: I am working in a Java environment using Spring Boot, where I often encounter scenarios where global variable state management is critical, especially within singleton services. I have ...
Muhammad Haris's user avatar
9 votes
5 answers
4k views

Writing public libraries: Should I let the consumer of the library enforce thread safety?

I'm writing a .NET library which exposes certain public APIs. Currently, I have not enforced thread safety in my library for following reasons apparent to me: locks (Monitor.Enter and Monitor.Exit) ...
Critical Failure- Core Dumped's user avatar
0 votes
1 answer
110 views

In Java's Fork/Join is the operation for combining results limited to addition?

As I understand it, the join() method merge/composes/combines the results from all subtasks. A simple example I saw was summing the numbers from 1 to N and the subtasks would simply sum a range of ...
releseabe's user avatar
  • 539
0 votes
2 answers
458 views

What problem does Rust's "atomic reference count" actually solve?

The Rust programming language offers a Arc atomic reference counting generic type for use in multi-threading environment, since Rc is optimized for performance in single-threaded applications, and ...
DannyNiu's user avatar
  • 219
1 vote
1 answer
102 views

Non blocking algorithm for invalidating and reloading cache in concurrent environment using Redis (with Redisson)

I'm trying to come up with a peace of code that would fetch centralised cache shared across multiple threads/app instances. Callers might come in swarms. The data is a large set, reads during ...
FoxMulder's user avatar
1 vote
2 answers
138 views

How to handle errors of pthreads fundamental lock und unlock functions?

I am writing a little C library for the Raspberry Pi for controlling 433MHz transmitters/receivers. While receiving data the whole application would block, so I decided to put this code into a ...
blackdog's user avatar
1 vote
2 answers
186 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() ...
CygnusX1's user avatar
  • 247
0 votes
5 answers
641 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 ...
tnsaturday's user avatar
1 vote
1 answer
639 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 ...
nick2225's user avatar
  • 157
0 votes
1 answer
512 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 ...
xyf's user avatar
  • 109
1 vote
4 answers
479 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 ...
mpAppProg's user avatar
0 votes
1 answer
73 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 ...
DimitrijeCiric's user avatar
0 votes
3 answers
1k 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 ...
Richard H. Nguyen's user avatar
1 vote
2 answers
754 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 ...
cylon86's user avatar
  • 111
4 votes
2 answers
829 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 ...
Avantgarde's user avatar
0 votes
2 answers
2k 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 ...
g00dds's user avatar
  • 111
1 vote
4 answers
3k 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 ...
das Keks's user avatar
  • 213
4 votes
3 answers
959 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 ...
Violet Giraffe's user avatar
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 ...
Dan's user avatar
  • 319
0 votes
2 answers
897 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 ...
dogma sucks's user avatar
7 votes
1 answer
439 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 ...
Quantum Guy 123's user avatar
0 votes
1 answer
119 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 ...
Lilian Shi's user avatar
0 votes
1 answer
233 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) ...
HateDread's user avatar
0 votes
0 answers
844 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 ...
Spring boot progammer's user avatar
3 votes
2 answers
3k 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/...
Anon's user avatar
  • 3,613
1 vote
0 answers
218 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> ...
Anon's user avatar
  • 3,613
0 votes
1 answer
240 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 ...
Nabiel Kandiel's user avatar
-1 votes
2 answers
90 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 ...
Justin's user avatar
  • 3
0 votes
1 answer
241 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 ...
James's user avatar
  • 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 ...
Paul Calcraft's user avatar
-1 votes
2 answers
234 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 ...
Wiktor's user avatar
  • 33
0 votes
2 answers
314 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 ...
FourtyTwo's user avatar
  • 119
1 vote
1 answer
641 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 ...
RamPrakash's user avatar
-2 votes
1 answer
175 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 ...
Maurice's user avatar
  • 133
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 ...
Chris's user avatar
  • 109
-1 votes
2 answers
1k 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?
moonman239's user avatar
  • 2,063
4 votes
1 answer
1k 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 ...
Dmitry Streblechenko's user avatar
0 votes
3 answers
495 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; } ...
Shadow's user avatar
  • 361
3 votes
1 answer
132 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 ...
Unknown1987's user avatar
0 votes
1 answer
2k 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 =...
Wballer3's user avatar
0 votes
1 answer
2k 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 ...
Mulciber Coder's user avatar
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 ...
Incomputable's user avatar
0 votes
3 answers
188 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, ...
Yann's user avatar
  • 119
2 votes
1 answer
396 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 ...
Patrick Wright's user avatar
20 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 ...
Kal's user avatar
  • 355
0 votes
0 answers
273 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 ...
Facundo La Rocca's user avatar
1 vote
2 answers
908 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 ...
Omar Gamil's user avatar
4 votes
2 answers
463 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 ...
underthevoid's user avatar
4 votes
4 answers
3k 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 ...
KhiladiBhaiyya's user avatar

1
2 3 4 5
14