Questions tagged [multithreading]
Multi-threading related questions including technique, structure, and safety issues.
672
questions
0
votes
2
answers
210
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 ...
0
votes
1
answer
76
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 ...
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'...
0
votes
3
answers
100
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 ...
0
votes
1
answer
45
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 ...
0
votes
2
answers
254
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 ...
1
vote
2
answers
121
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 ...
4
votes
2
answers
694
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 ...
1
vote
1
answer
253
views
Using python on a Raspberry Pi, how do I record video and keep reading other sensors simultaneously?
For my system I would like to record constantly, which independently I can do. Additionally, I need to be constantly reading some sensors (using SPI), which independently I can also do.
My present ...
0
votes
1
answer
1k
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 ...
6
votes
2
answers
1k
views
Erlang or 'x'.. Is it worth it (vs. Python w/ GIL)?
So, I've finally gotten myself to a point where I'm comfortable enough with Python (using Pyramid as my framework of choice) to undertake a rather large personal project. As it's a personal project, I ...
1
vote
3
answers
372
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; }
...
0
votes
4
answers
9k
views
Is it ok to restart a BackgroundWorker inside its Completed event
I want a background worker to continue running and occasionally update the user interface. My first idea was to use a BackgroundWorker and in its completed event just fire it up again.
Is using a ...
0
votes
2
answers
330
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 ...
0
votes
1
answer
1k
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 ...
79
votes
1
answer
22k
views
Is there a difference between fibers, coroutines and green threads and if that is so what is it?
Today I was reading several articles on the Internet about fibers, coroutines and green threads, and it seems like these concepts have very much in common, but there are slight differences, especially ...
0
votes
2
answers
339
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 ...
4
votes
3
answers
349
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 ...
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 ...
-1
votes
1
answer
1k
views
How can I represent with UML a process that involves queues?
I would like to use UML diagrams to show some processes I am designing and would like to implement.
The processes involve using a queue, and adding and taking out elements from it.
In one of this ...
-1
votes
1
answer
211
views
How should a client handle receiving data from a separate thread?
There are plenty of tutorials on the internet on how to build a server that handles its clients through the creation of separate threads, but there is no tutorials (at least I couldn't find any) on ...
2
votes
3
answers
142
views
Clarification on Acquire/Release Semantics in multithreaded programming
In an attempt to fundamentally understand any concept, I try to understand the meaning of the words within the context it is being used. Currently, I am trying to fundamentally understand the whole ...
7
votes
1
answer
354
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 ...
11
votes
7
answers
5k
views
Why are threads called threads?
I understand that a process a unit of resource ownership and executable instructions. Threads allow a process to share its resources with multiple executions, and it's easier for an OS to schedule ...
2
votes
2
answers
383
views
Notify Millions of subscribers at the same time(or with min. delay) in C++?
I'm working on a problem, in which i have some real time weather information of different cities through out the world. I'm exposing subscribe function to interested people/clients, with input:- ...
3
votes
3
answers
8k
views
Implementation strategies for atomic counter
I basically have a counter variable that is decremented and frequently polled. There are three options to implement that, that I can think of:
Number 1:
private volatile int count;
public void ...
0
votes
1
answer
74
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
191
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
1
answer
1k
views
Best Way To Take multiple TCP Connections, Read the Incoming Data, and send that Data back into the Main Thread in Golang?
I want to take data from my goroutines and add them back to the main thread/goroutine. Problem is that I need the goroutines to stay open because data can come through the connection at any time in ...
0
votes
0
answers
639
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
1k
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/...
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 ...
1
vote
0
answers
148
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>
...
0
votes
1
answer
223
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 ...
-1
votes
1
answer
524
views
What operating systems use both a Render thread and a UI thread? [closed]
Microsoft employees commonly describe Windows 8 as having both a Render thread and UI thread.
Typically they say the Render thread performs animations and the UI thread handles most other operations: ...
16
votes
3
answers
11k
views
How will C# 5 async support help UI thread synchronization issues?
I heard somewhere that C# 5 async-await will be so awesome that you will not have to worry about doing this:
if (InvokeRequired)
{
BeginInvoke(...);
return;
}
// do your stuff here
It looks ...
0
votes
1
answer
154
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
89
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
817
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 ...
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
243
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
182
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
108
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
317
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
424
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 ...
-2
votes
1
answer
172
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
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 ...
-1
votes
2
answers
691
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
413
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 ...