Questions tagged [multithreading]
Use this tag when the program performs its work using multiple concurrent threads of execution.
1,589
questions
15
votes
2
answers
2k
views
Block-free priority lock
Background
I wanted to write an event loop that supports scheduling, but found that no implementation of priority queue that I know of supports waiting on a condition variable (the idea is that the ...
3
votes
1
answer
395
views
Leaky Bucket algorithm with concurrency
Trying to mimic a scenario where multiple threads are creating the traffic to fill the buckets & a thread which leaks the bucket at a specified rate.
Could you review this code?
...
0
votes
1
answer
96
views
Implementing Database Connection Pooling
I am re-implementing a web-application, partially as a learning exercise to learn nim as well as multi-threaded programming. As part of that learning exercise, I want to implement connection pooling ...
1
vote
1
answer
65
views
c++ multithreaded message broadcaster with link lifetime management v2
note: This is v2 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?). Code is ...
1
vote
1
answer
59
views
c++ multithreaded message broadcaster with link lifetime management
note: A version of this code without link lifetime management was previously reviewed. Adding lifetime management actually made the code simpler, and the class simpler to use.
I have written a class ...
1
vote
1
answer
58
views
Dividing shared resources for homogeneous multithread processing
I'm trying to implement a homogeneous multithreading example that multiple threads process portion of a huge task. In order to achieve this, I thought of clustering data/resource and multiple threads ...
4
votes
1
answer
135
views
Binary Thread Scheduler
The term, I used, binary thread scheduler means a scheduler that orders the execution of two threads for two tasks that has a specific dependency. Rather than using some mathematical expressions to ...
1
vote
2
answers
943
views
sum of array using multithreading
I implement sum element of array using multi threading but my question is when my program work with one thread the time is better than using 6 thread . I am using a CPU with 8 threads.What am I wrong
<...
0
votes
1
answer
53
views
Type-agnostic abortion condition in Producer-Consumer model queue
This is a follow-up post to the topic discussed here.
Description
I am trying to implement a robust, multi-threaded producer-consumer model with a single producer in the main thread and several ...
5
votes
1
answer
977
views
Multithreaded Producer-Consumer model implementation
Description
I am trying to implement a robust, multi-threaded producer-consumer model with a single producer in the main thread and several consumers in other threads.
The generator thread loops over ...
1
vote
2
answers
415
views
Replacement for starting threads from a for loop
I have the following code:
...
2
votes
0
answers
552
views
Parallel Breadth First Traversal in Rust
Overview
I have been writing my own graph API for Rust and one thorny problem I wished to tackle was a
parallel breadth first traversal of the graph. The API itself will have different graph
flavours, ...
2
votes
1
answer
240
views
Producer/Consumer Multi-Thread implementation - Is the solution correct?
I recently faced this following question in a Java coding round, needless to say I did not get a callback. So I want to know where I am going wrong in my solution and also what can be done to improve ...
11
votes
3
answers
2k
views
Multi-threaded web server serving HTML, images, etc
I have a web server that can send websites, images, mp3 and other things and I was wondering how I could improve the code and make the server more efficient.
...
2
votes
2
answers
1k
views
Sum of 2 arrays using multi threading
I'm trying to implement sum of 2 array using multi threading.
I expected that when I use more threads it will be faster than when I use one thread, but that isn't the case.
...
5
votes
2
answers
3k
views
C++20 Thread Pool
I've implemented a thread pool using C++20. I'm fairly new to concurrently/multi-threaded programming and wanted to work on a project that I could learn from while also getting to know some of the new ...
2
votes
0
answers
694
views
Multi-producer/single-consumer queue in Python
I am currently working on a problem that involves multiple producers and a single consumer through a queue object. The following list is about a few things that's special about this problem:
One ...
3
votes
1
answer
725
views
Real time histogram using multithreading (Qt + Qwt)
I'm writing a GUI for different VME modules (electronics). There are several of them which are used for the data acquisition. For example, an ADC produces the digitized maximum voltage on its input. ...
3
votes
2
answers
197
views
C++11(14/17/20) Thread Management
I'm implementing something of a thread janitor in modern C++. What I've got works, and while it's not organized in the way I'd like yet, I'd like some feedback on the fundamentals. Thank you in ...
3
votes
2
answers
387
views
C++11 revised `std::latch` implementation
This question follows up on this question.
After turning the while-loop into a conditional wait using std::condition_variable, I ...
1
vote
1
answer
288
views
Implementation of a latch
As an exercise to learn more about multi-threading and atomic operations work in C++, I decided to implement a latch class in C++11 loosely based off of std::latch ...
1
vote
1
answer
727
views
Printing odd and even numbers in separate threads C++
I recently saw a youtube video on printing even and odd numbers from 0 to 100 in Java. https://www.youtube.com/watch?v=eRNTx8k5cmA
Thread 1 prints even numbers and thread 2 prints odd numbers. Both ...
0
votes
1
answer
65
views
Showcase difference multiprocessing and threading in Python
This week I dived into the issue of speeding up my program by either threading or multiprocessing. I did not understand well the difference between the two, but that became quite clear when I got the ...
4
votes
2
answers
803
views
2 Threads taking turns printing the alphabet
I am supposed to write code for an assignment. The goal is to make 2 threads (which are objects of a class that implements runnable) take turns printing the alphabet. One of them prints upper case ...
1
vote
1
answer
50
views
Mean and variance of element-wise distances in a set of multi-dimensional arrays in Matlab
This is a follow-up question for Calculate distances between two multi-dimensional arrays in Matlab. Given a set SX
$$
S_{X} = \{ { X_{1}, X_{2}, X_{3}, \dots, X_{n} } \}
$$
where n is the count of ...
2
votes
1
answer
862
views
Hashing with python optimization, hashlib and multiprocessing
I am looking to get any type of improvement, I want to be able to hash a list of 'blocks' aka strings and check if hashes match per block, if you can help me with that, currently reading and writing ...
1
vote
1
answer
141
views
pointer jumping on a GPU using Aparapi
Classic pointer jumping algorithm summarizing values from an array adapted to run on a GPU instead of a PRAM.
Read about openCL and Aparapi yesterday for the first time, so this is my first trial: ...
5
votes
3
answers
186
views
Python 3 Multi-connection downloader
I have written a fully functional simple command line multi-connection downloader, written in Python 3, using just threading, ...
-1
votes
2
answers
181
views
A simple java game engine [closed]
I'm starting an object orientated game engine in Java. My plans for the engine is to be able to split things easily into multi-core loads. My idea is that a Unique (interface with a ...
2
votes
2
answers
327
views
Avoid global variable due to executor.map()
I'm pretty new to python but after watching Mr Robot I felt inspired to make a CLI portscanner. With all the fancy console outputs you see in movies like a progress bar.
It's finished and works nicely ...
2
votes
1
answer
123
views
Multithread or multiprocess [closed]
This is my code:
...
1
vote
1
answer
268
views
Validate Empty Sudoku: Multi-Threaded Solution
The problem is that we have an unsolved sudoku board, and we want to validate it, we need to check each column, row and sub-square.
Here we represent a empty cell with -1.
My idea was to create a ...
4
votes
1
answer
527
views
Python multi-connection downloader
This is a simple Python multi-connection downloader primarily using requests, mmap and threads, it downloads a single file using 32 concurrent connections, slices the download using range parameter, ...
4
votes
2
answers
161
views
Longest Palindromic Subsequence Multithread in C
I'm trying to learn how to multithread with c, and thought that the longest palindromic subsequence problem would be a good place to start.
The idea is that we run two threads and compare their ...
-2
votes
1
answer
96
views
Thread-safe collection to store Member objects [closed]
This is poorly written Java code, intended to implement a thread-safe collection to store Member objects and failing at doing so.
...
1
vote
0
answers
48
views
Thread-safe running mean and variance
In one of my personal python libraries I have a custom class used for computing the running average and variance of a stream of numbers:
...
1
vote
1
answer
94
views
Daily coding problem: Job scheduler invoking a function after specific time
This is a problem from Daily Coding Problem. I have implemented it in Java.
For a function f I have used Runnable interface.
...
6
votes
1
answer
551
views
C++ producer-consumer using blocking buffer
I'm working on a programming exercise (university, nothing related to industry) which basically asks to implement a Buffer to be used by two threads (a producer and a consumer). The first one enqueues ...
2
votes
0
answers
39
views
How to check gcp pupsub empty/inactitve subscribtion
I have an application that subscribes to a topic in GCP and when there is some messages over there it downloads them and sends them to a queue on ActiveMQ.
In order to make this process fast I am ...
1
vote
2
answers
776
views
Using multithreading to send multiple emails
I'm trying to send any number of emails in the shortest amount of time using .NET 5.0?
I've been playing with something like the following but I am not sure if it is optimal or even correct as there ...
0
votes
1
answer
672
views
An async time-based rate-limiting semaphore for C#
This is a class that allows only limited number of requests to proceed per period of time.
This is designed for use with external APIs that require such rate limiting, e.g. 600 requests per 10 minutes....
0
votes
1
answer
330
views
Python best practices to impletent QThread, progressbar (pyqt5) and sniffer (scapy)
I'm new in python and I want to know the way to improve this code with best practices.
I'm using PyQT5 to create new thread
In that thread I'm using scapy to sniff traffic and filter ARP traffic to ...
2
votes
0
answers
49
views
Rust program to create mail.tm accounts
I have created a rust program to create https://mail.tm accounts, but I think there are things I could have done better. Are there things I can do to improve performance? Are there any unnecessary ...
22
votes
3
answers
6k
views
C++ lock-free, MPMC Ring buffer in C++20
I have some performance critical inter-thread messaging code in C++. Multiple producers, one or more consumers.
Profiling dozens of iterations of this messaging code over several years of development, ...
1
vote
1
answer
108
views
C++ Improved ThreadGroup Implementation
After the amazing feedback from these questions; I have prepared a third version of the original posted code.
The Idea is the same: An std::size_t variable ...
3
votes
2
answers
295
views
C++ ThreadGroup Implementation
Edit: An improved code based on feedback is available here.
As a kind of sequel to the previous question, here is an improved version( with clarified naming ). The Idea is the same: An integer ...
2
votes
3
answers
494
views
A file system watcher class for on-fly file reloading when it has been modified
I wrote a file sytem watcher class that is used to monitor file modification and then execute user-defined handler. Other file system events like moving or deleting don't need to be monitored. The ...
3
votes
2
answers
486
views
C++11 ThreadPool implementation
A new version of this code based on the provided advice can be found here.
Latest improvement is found here.
I made a simple ThreadPool implementation in C++ using ...
-1
votes
2
answers
1k
views
Thread-safe LRU cache in Python
I've written a simple LRU cache class and I am trying to make it thread-safe. My thoughts are that I just need to wrap the code that updates the ordered dict in a lock so that if any thread is writing ...
3
votes
1
answer
174
views
Particle swarm algorithm with multiple threads
I wrote a simple multitthreading program which does particle swarm optimization. Optimization itself and some corresponding functions were taken from https://nathanrooy.github.io/posts/2016-08-17/...