Questions tagged [multithreading]

Use this tag when the program performs its work using multiple concurrent threads of execution.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
25 views

Counting unfair semaphore implementation in Java [closed]

I am implementing Java's Counting Semaphore's acquire() and release() methods and using it in a multi-producer-consumer problem. Semaphore class ...
vvs14's user avatar
  • 1
2 votes
0 answers
11 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 ...
cpicanco's user avatar
  • 499
4 votes
2 answers
76 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 ...
Ders's user avatar
  • 43
1 vote
0 answers
43 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 ...
PilotGuy's user avatar
5 votes
1 answer
365 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 ...
mascai's user avatar
  • 369
4 votes
1 answer
96 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" ...
Bula's user avatar
  • 359
1 vote
0 answers
34 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 ...
dimo414's user avatar
  • 387
0 votes
0 answers
100 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 ...
Bernardo1r's user avatar
2 votes
1 answer
181 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 ...
Szyszka947's user avatar
2 votes
1 answer
98 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): ...
Oersted's user avatar
  • 299
7 votes
1 answer
960 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 ...
Oersted's user avatar
  • 299
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 ...
larssonmartin's user avatar
2 votes
1 answer
62 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 ...
Aviad P.'s user avatar
  • 123
-1 votes
2 answers
85 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 ...
Max's user avatar
  • 7
0 votes
1 answer
120 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: ...
zwhconst's user avatar
  • 137
4 votes
2 answers
118 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....
M. Saintourens's user avatar
3 votes
1 answer
74 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 ...
Goubermouche's user avatar
1 vote
1 answer
103 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: ...
1f604's user avatar
  • 113
1 vote
0 answers
50 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: ...
coderodde's user avatar
  • 27k
0 votes
0 answers
37 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 ...
Richard Neumann's user avatar
3 votes
2 answers
459 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, ...
user274177's user avatar
1 vote
1 answer
65 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 ...
mindoverflow's user avatar
2 votes
1 answer
105 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 ...
chubercik's user avatar
  • 123
1 vote
1 answer
90 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 ...
Kevin's user avatar
  • 123
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. ...
Darth-CodeX's user avatar
4 votes
1 answer
309 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. ...
rickmanalexander's user avatar
2 votes
2 answers
161 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 ...
Haaput's user avatar
  • 23
6 votes
1 answer
347 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 ...
EternalLlama's user avatar
3 votes
1 answer
226 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 ...
c.leblanc's user avatar
  • 253
6 votes
2 answers
818 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 ...
andylvua's user avatar
  • 163
4 votes
2 answers
188 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 ...
Shmuel Newmark's user avatar
0 votes
1 answer
116 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): ...
Volo's user avatar
  • 101
7 votes
2 answers
783 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. ...
Edziju's user avatar
  • 299
3 votes
1 answer
2k 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 ...
jezza's user avatar
  • 205
7 votes
1 answer
216 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, ...
Macmade's user avatar
  • 171
2 votes
1 answer
116 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 ...
Ben's user avatar
  • 21
0 votes
1 answer
81 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 ...
Student's user avatar
3 votes
1 answer
321 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 ...
rioki's user avatar
  • 452
4 votes
2 answers
230 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 ...
Lee's user avatar
  • 43
1 vote
1 answer
150 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 ...
Node.JS's user avatar
  • 389
6 votes
2 answers
389 views

c++ multithreaded message broadcaster with link lifetime management v3

note: This is v3 of code that was previously reviewed. I have written a class that handles listeners registering callbacks to receive messages. Link lifetime is managed (or is it? See below). Code is ...
Diederick C. Niehorster's user avatar
3 votes
1 answer
1k views

Use a static field for cache an authentication token in .NET API

I have a .NET 6 web API that does some requests to another third party API, this API has a token that expires after a few hours, so I want to cache this token and reuse in the requests. Here how I ...
Vanderlei Morais's user avatar
3 votes
1 answer
122 views

A mutex that can detect certain types of programming error

This mutex prevents concurrent access to a target resource. One key requirement is the ability to be acquired in a (scheduler) thread and released in a different (worker) thread. Unfortunately this ...
Raffaele's user avatar
  • 131
2 votes
1 answer
106 views

Multithreaded segmented Sieve of Eratosthenes

I am fairly new to Rust and thought a good way to practice would be to write a multithreaded segmented Sieve of Eratosthenes. It performs ok (searches ten-billion numbers in about 11 seconds on my ...
knots427's user avatar
2 votes
1 answer
57 views

Force acquiring R/W lock

I am trying to build an abstraction that forces lock acquisition before data can be accessed. This seems to work, but please tell me if what I am doing horribly wrong, and what I could improve. I am ...
optimistic's user avatar
1 vote
2 answers
82 views

multithreading LRUcache in C++

I want to implement a multithreading LRU cache in C++. And here is the code. Can you tell me what should I do to make it more multithreading? ...
Jacob's user avatar
  • 111
3 votes
2 answers
99 views

Fast portable, parallel MSD radix sort for unsigned keys in C89

Now I have this portable, parallel MSD radix sort for unsigned keys. It exhibits linear speedup on small values of \$P\$ and has a running time of $$ \Theta(N/P + P)...
coderodde's user avatar
  • 27k
4 votes
2 answers
676 views

Traffic simulation GUI: an exercise in concurrent programming using threads

To avoid a code dump I have removed most of the code and left the first few lines of constructors and methods and anything relevant. Full code at the bottom. The purpose of this code is to use threads ...
Corey Hodges's user avatar
1 vote
1 answer
104 views

Timeit multithreading/multiprocessing C++

Given a Timeit method which runs for n times the provided function, which approach between multithreading and multiprocessing should be better to speed up the execution of all iterations and avoid the ...
BloomShell's user avatar
2 votes
2 answers
204 views

the multi-threading of adding all the values from a random generated vector

I currently am creating a vector and fill it with random values( for this case the random values will be 1) once the vector is created i want to calculate the total sum which should be 100000000, I am ...
Keanu.c's user avatar
  • 21

1
2 3 4 5
32