Questions tagged [multithreading]
Use this tag when the program performs its work using multiple concurrent threads of execution.
1,589
questions
1
vote
2
answers
131
views
Thread-safe int wrapper in c#
My system is a .NET Core 7 console app, which starts some background threads. I need to pass some int values (counters, etc.) between the main and background ...
3
votes
1
answer
104
views
C++ implementation of a concurrent queue and of a thread pool
I am working on an implementation of a concurrent_queue<T> and pf a ThreadPool, see beneath. The objectives are CPU ...
1
vote
0
answers
37
views
Telegram bot computing a heavy I/O task
Introduction
I have a telegram bot based on aiogram framework. It does GPU intensive computations locally then user makes a request and outputs a text file after ...
4
votes
2
answers
344
views
Class for locking shared disk directory
I'm writing an application to sync files between two directories. In order to prevent simultaneous access to the shared directory from several computers, I implemented blocking of the shared directory....
11
votes
4
answers
2k
views
Simple Key Value Database using C
I was recently doing an assignment for a job interview, which asked to create a simple key value database with 4 command line operations:
create key value: Adds a key value pair/updates an existing ...
3
votes
1
answer
70
views
Multi producer/consumer lock-free queue
I would be grateful if you could review my code for a multi producer/consumer lock-free queue in C++.
I am mainly after performance improvements, but all input is welcome.
...
1
vote
0
answers
39
views
Tkinter threadpool with callback implementation - alternative approach feedback
This is an attempt to create a usable alternative to the "normal" method of implementing concurrency with tkinter. The "normal" method seems to be by pro-actively polling a result ...
0
votes
1
answer
29
views
Handling multiple socket communication in Python Client-Server application [closed]
I'm developing a client-server game application in Python. Here's the scenario:
Clients connect to the server and register.
After registration, all clients see a main menu.
One client can initiate a ...
3
votes
2
answers
165
views
Multithreaded disk scan
I'm writing an application to compare and sync folders on a disks. Scanning the contents of folders is performed in separate threads. I wrote a class to manage scan threads.
The main application class ...
0
votes
1
answer
171
views
Why is this not considered better way than Async Await
After so many searches and back-and-forth attempts, I have developed an TCP Server to listen to the network stream and it is working fine. So kindly review the code, and please let me know if this ...
2
votes
2
answers
122
views
Thread-safe coordinate holder
I have been given a task to create a thread-safe RobotCluster class. The idea is that there's a set of robots operating on multiple threads and they each submit the ...
2
votes
0
answers
16
views
Recording/Playback thread device in Object Pascal
I have developed an audio recording and playback base device in Free Pascal. This device is built on Free Pascal's TThread class and utilizes the low-level audio ...
4
votes
2
answers
79
views
C++ Neuron Spike Raster Deserializer
Please help me establish a solid foundation for this computational neuroscience project. I'd like to make sure I'm moving forward with something reasonable before I begin tackling the more complex ...
1
vote
0
answers
71
views
Optimizing tokio and pcap Operations in Rust for Max Throughput
Background
I'm mostly a c# and python programmer and am slowly learning Rust. I'm not sure if that is contributing to incorrect concepts as to how threading and io work in Rust, but that's what I'm ...
5
votes
1
answer
401
views
Print abcabc... in three threads
I want to implement the following case
Input - integer number n
Start 3 threads. The first thread prints 'a', the second prints 'b', the third prints 'c', then the ...
4
votes
1
answer
109
views
Packet generation and consumption
I have the following simplification of a program which consists of 2 threads. One thread pushes packets to the back of a deque while another waits for user input before performing a "heavy" ...
1
vote
0
answers
36
views
Handling a subprocess' output in background threads and accepting user-provided sinks for the output
I have a PR swapping from Command::output() to a custom implementation using threads to handle the subprocess' stdout/stderr while the program is running, instead ...
0
votes
0
answers
105
views
For loop vs If statement using conditional variable
I'm extending the sync.Pool type by limiting the amount of objects that can reside outside the pool. To achieve this I'm using ...
2
votes
1
answer
359
views
Parallel handling db queries is very slow in C#
I have SignalR app that publishes sent messages to Redis. My console app subscribe to channel where these messages are sent, deserializes it and saves in database.
Problem is with handling these ...
2
votes
1
answer
100
views
C++: algorithm that uses fixed-size buffer of data that are produced in stream, faster than the algorithm speed; modified version
This is a, I hope, an improved version of this code, limiting atomic usage (following @GSliepen, @G.Sliepen advice) (NB I'm limited to, at most C++17):
...
7
votes
1
answer
1k
views
C++: algorithm that uses fixed-size buffer of data that are produced in stream, faster than the algorithm speed
I try to implement this scenario with a producer/consumer multithread pattern and I'd like to optimize synchronization and memory model directive used.
This code originates from a SO question and its ...
5
votes
3
answers
2k
views
An exercise in Data Oriented Design & Multi Threading in C++
Been working in games development professionally now for about ~5 years, but have only been doing OOP & haven't worked with multi threading before as I'm mostly a gameplay programmer, I've also ...
2
votes
1
answer
70
views
Single worker, multiple async callers in different threads
My use case is this:
There is a long running process that I want to ensure is only ever running at most only a single time.
Multiple consumers from different threads may wait on the calculation.
If ...
0
votes
2
answers
109
views
Web scraping spider
I'm currently working on my first web scraping project and I need to scrape a lot of websites. With my current code it takes more than a day but for my project I need to scan the same websites every 5 ...
0
votes
1
answer
125
views
C++ slim condition notifier
When writing multi-threading code, one often need the thread to wait for some condition being met. A naive approach would look like this:
...
5
votes
2
answers
127
views
Get files downloaded asynchronously after double clicking on list item (C++)
The problem I am trying to solve as an exercise is as follows:
I have a UI running in the main thread, specifically a list view with many items. Each item represents a file that the user can download....
3
votes
1
answer
85
views
Parallel semi-sequential bottom-up tree traversal algorithm
I'm trying to traverse a tree-like structure from the bottom-up, and in parallel. Due to some other constraints I also have to allow for thread counts that may be lower than the width of a given set ...
1
vote
1
answer
158
views
Multithreaded O_DIRECT file read-and-process program
Here is my code. It reads a file and returns the sum of all the bytes in the file:
...
1
vote
0
answers
60
views
A parallel MSD radix sort in Java for integer keys
I have this repository: https://github.com/coderodde/ParallelRadixSort.java/tree/main
It contains a parallel MSD radix sort presented below:
...
0
votes
0
answers
38
views
Trait to extend iterators with parallelized mapping function
Working on a project of mine, I wanted to parallelize mapping operations on an input stream. I found pariter on crates.io but it did not fit my needs, because its generic's bounds require the iterator ...
3
votes
2
answers
544
views
New York Times' Digits Game Solver
I wrote an algorithm to solve the New York Times' Puzzle: Digits.
You could play the game here.
The rules of the game are as follow:
You were given 6 numbers and you could use simple operations (plus, ...
1
vote
1
answer
101
views
Rate-limited thread scheduler in Java
Background: I'm planning to call different endpoints of a website's API quickly, but the usage policy implies that I may only make five calls in a second. I can't rely on the calls taking 200 ms on ...
2
votes
1
answer
116
views
Parallelization of the tick function in a Game of Life simulation using Rust and Python (+ NumPy)
I've been writing a small Rust module recently with the sole purpose of speeding up my Python program, which is a Conway's Game of Life simulation. The function written in Rust is called from Python ...
1
vote
1
answer
110
views
C++ Dynamic Balancer on a Threadpool
I have a Balancer Class in my project which should dynamically increases/decreases the amount of Worker Thread based on the current amount of Messages which are ...
4
votes
2
answers
1k
views
Multi-threading Class in C++
I wrote a C++ class which can take a vector of functions and their respective arguments and execute them in parallel and return a vector of results from its respective functions.
...
4
votes
1
answer
509
views
Threadsafe Non-Overlapping Timer
I was working on a project recently, where I needed to process some tasks periodically, but the execution of those tasks could not overlap with one another. ...
2
votes
2
answers
269
views
Code for asynchronous data stream processing with multistage pipelines
I am trying to write some code for processing streams of asynchronous data from multiple sources (Producer Nodes), process them ...
6
votes
1
answer
388
views
Synchonizing queue with mutex
I am trying to syncronize the queue between threads using mutex. I have 2 mil random integers in input.txt file. Main thread reads integers then puts them in queue. Other threads are simultaneously ...
4
votes
1
answer
332
views
Multithreading a shortest path algorithm
I would like to modify my shortest path finding code to use multithreading and improve its performance. The algorithm must be able to work with negative weights, and as a result, we cannot use ...
6
votes
2
answers
1k
views
C++ Thread Pool Implementation using Lock Free Queue
Topic: C++ Implementation of Lock-Free Queue and ThreadPool classes
In a project I'm currently working on, I need the implementation of ThreadPool along with a thread-safe queue. I've tried ...
4
votes
2
answers
226
views
Multithreaded Conway's Game of Life implementation written in C and Java using JNI
I had some multithreading C programming experience from school last year but I wanted a bit more so I tried to program a Conway's Game of Life implementation from scratch.
Code is mainly written in C ...
0
votes
1
answer
141
views
Lock-free implementation of getAndUpdate() using atomic CAS (Compare-And-Swap) operation
We have the following class written in Kotlin Native with the new Memory Manager (which doesn't require to freeze objects):
...
7
votes
2
answers
813
views
ThreadSafe std::queue
I have written a threadsafe queue and I would like you to suggest what can be improved and how to write good unit tests for this implementation.
...
3
votes
1
answer
3k
views
Safely starting and stopping a thread owned by a class
If I have a class running its own thread, I almost always try to write it like the following, with the thread started by the constructor. The reason for this is that an object can never be constructed ...
7
votes
1
answer
303
views
C++ mutex-like class using std::condition_variable
On a project I'm working on, I have a need for a mutual-exclusion primitive behaving like std::mutex or std::recursive_mutex, ...
2
votes
1
answer
124
views
DFS Maze Solver
I am new to Rust Programming so I decided to implement a Maze Solver using DFS. I was wondering if there is any way to optimize this code further
...
0
votes
1
answer
131
views
Training a Reinforcement Learning algorithm
Problem:
I'm trying to reduce the computation time and optimize specific functions of a Reinforcement Learning algorithm in the training phase and observed that one block of code takes too much ...
3
votes
1
answer
453
views
jthread drop-in replacement
I have a couple of libraries that use jthread, but also are published via vcpkg. The problem I have is that both github and vcpkg's AzureDevOps CI have a version of clang that does not have jthread ...
4
votes
2
answers
248
views
Multiplayer queue optimisation
I currently have code that is working but I think it can be optimised.
The code waits until a player joins and adds the player to a BlockingQueue if there is
not already a Player waiting then it ...
1
vote
1
answer
187
views
Dining philosophers problem using just lock without semaphore in C#
I am trying to solve the Dining philosophers problem in CSharp. I didn't use any semaphores and it looks like it's working. I am wondering 1) if my code deadlock is safe and 2) if can I please get ...