Skip to main content

Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
8 votes
0 answers
129 views

Movie Barcode Generator

Task I wrote a movie barcode generator in C++ using OpenCV. Self-described engineer, space lover and tea drinker Thomas Poulet defines a movie barcode as follows: A Movie Barcode is the color ...
1 vote
0 answers
26 views

Java multithreading with Spring JPA

I have to improve a process that is currently sequential, and i wanna make it multi-thread. This process uses Spring JPA, with spring boot 2 and java 17. I would like to have a feedback on the ...
9 votes
2 answers
1k views

A TCP server which uses one thread to read while writing data with another thread

The TCP server in the code snippet below is designed to: Read data using one thread while writing data with another thread. Allow only one client to be connected at a time. Automatically close the ...
2 votes
2 answers
71 views

A thread-safe performant Money Transfer API in Java

This is a popular interview question. It is meant to be done within 30 minutes. The task is to implement a thread-safe performant Bank Account API that allows to transfer, deposit, withdraw and check ...
7 votes
2 answers
148 views

"Polite" internet connectivity check on separate thread

I wrote this class that checks for internet connectivity on a background thread. Targeting Python 3.10. It has two main design goals: Minimize the time get_state() ...
0 votes
1 answer
75 views

Take photographs using simulated cameras that share a lock

I'm new to threading in Python. I want to use it to speed up taking images on my lab computer. I have the following dummy code: ...
5 votes
1 answer
354 views

Mutex lock benchmark

I'm trying to measure how many CPU cycles a mutex lock takes. Can you find any problems in my mutex lock benchmark? ...
4 votes
1 answer
87 views

Multithreaded Alpha-beta pruning for playing Connect Four in Java

Intro (The entire repository is in GitHub.) This time, I have parallelized the famous Alpha-beta pruning algorithm. The idea is that the parallel algorithm descends in a game tree (at least) 2 levels ...
7 votes
2 answers
1k views

A thread-safe performant URL Shortener in Java

This is a popular interview question. It is meant to be done within 45 minutes. The task is to implement a thread-safe performant in-memory URL Shortener. My implementation is based on two maps that ...
1 vote
1 answer
82 views

Kotlin Compose authentication with Google and Facebook using a CircularProgressIndicator for UI loading

I had this problem: https://stackoverflow.com/questions/78528358/how-to-prevent-circularprogressindicator-from-freezing-during-authentication-in Now after fixing it, I want to make sure that this is ...
3 votes
3 answers
5k views

Running multiple producer and single consumer in a multithread environment

I have a below class in which add method will be called by multiple threads to populate messageByChannelReference concurrent ...
20 votes
1 answer
1k views

Messed up Elevator Management System

In light of our current community-challenge I decided to build an Elevator Management System. Initially I intended to program the EMS like a real-time operating system and the elevators as finite-...
3 votes
1 answer
61 views

how to launch multiple processes efficiently

I have a list of car models which I want to simulate by launching multiple instances of an external simulator executable. My application stores the current status of all the cars that are being ...
3 votes
1 answer
94 views

Multithread execution times are slow on Ubuntu and fast on Windows

I'm working on a project accelerating the execution of a Genetic Algorithm both on multiple cores and on a GPU. The algorithm is specifically suited for the solution of the Traveling Salesman Problem ...
10 votes
4 answers
4k views

Portable periodic/one-shot timer thread - follow-up

This is a much improved version (I hope) of code in this previous code review of mine. I have: renamed several things. Are the names good? made it lazily start the worker thread only after the first ...
4 votes
1 answer
763 views

Rust publish/subscribe channel library

I've written a simple multiple-sender multiple-receiver channel, but I'm unsure if my approach is the best way to do this. I'm not using multi-threaded primitives but instead wrapping around std's ...
7 votes
1 answer
274 views

Multithreading message queue system

For an application I'm developing, I need an system which allows a thread to submit messages to another thread. For this purpose I designed a message queue system with the following features. Any ...
5 votes
3 answers
98 views

Time based cache for single element

The container should be thread safe and provide lazy load of data, and cache the data for set period of time. ...
5 votes
1 answer
169 views

PasteBin API scraper for new public pastes that appear at regular intervals

I'd like to optimize my code and get a better understanding of how I can perform the task I am doing better. I've only used Perl threads about 3 or 4 times now. The purpose of my code block is to ...
1 vote
1 answer
43 views

Multi-threaded Error Handling Data Fetching Script

I've been working on a Python script that fetches student data from an API using multiple threads for concurrency. The script retrieves both student information and prospectus data and saves them to ...
3 votes
1 answer
3k views

Implementation of Concurrent List in .NET

I would appreciate review of this implementation of the concurrent list that is, to my knowledge, currently missing in .NET Core. Requirements Thread safe Lock free Ordered Supports get and set by ...
0 votes
0 answers
44 views

Thread pooled bidirectional breadth-first search in Java for graphs with slow node expansion - part I/II: the algorithm

(This post has part II/II.) Intro This time, I have this GitHub repository. The idea is that if the graph node expansion is slow (for example, in the case where you ask a web server to return some ...
5 votes
2 answers
608 views

Generic multithreading solution for improving the performance of slow tasks

I'm currently in the process of replacing an archaic multithreading solution using some of the newer C++ standard library features now that our software has been updated to use C++20. Previously, most ...
1 vote
0 answers
88 views

Feedback on a ThrottledInvoker class

State in a Fluxor app can be updated many times per second, with each change triggering a render in Blazor. I wanted to write a class that would throttle these notifications so they don't occur more ...
1 vote
1 answer
76 views

Multiple Producer and Multiple Consumer Implementation Using Locks and Semaphore

This solution has a total of four classes. Main.java: Class with main method. Execution starts here. ...
8 votes
1 answer
268 views

Python asyncio multithread wrapper

For my application, I needed a lightweight way to launch multiple tasks and monitor their completion in a main loop periodically or use callbacks. The main loop is going to be busy most of the time ...
3 votes
1 answer
136 views

C++ inline minimalist thread pool

This is a "minimal thread pool" I came up with to compare with a colleague's approach using Rust's Rayon's par_bridge() to automatically parallelize ...
4 votes
1 answer
339 views

Golang function that reads S3 files and populates maps with strings as keys

I have a below read function which is called by multiple go routines to read s3 files and it populates two concurrent map as ...
3 votes
1 answer
241 views

Logging in a different thread using circular buffer C++

What it does The code creates a logger class which instantiates a circular buffer at construction and uses producer-consumer style approach using condition_variable to log and print the messages to ...
2 votes
1 answer
71 views

Multithreaded natural language text parser (Rev.2)

This is the second iteration of the Multithreaded natural language text parser code review. Special thanks goes to G. Sliepen who conducted the first review. Before reading this post, please read the ...
1 vote
1 answer
286 views

Design a thread-safe Hit Counter

I have designed a Hit Counter which can conveniently be used to design a Rate Limiter Original question: https://leetcode.com/problems/design-hit-counter/ To make it thread safe, I used lock statement....
2 votes
1 answer
109 views

Multithreaded natural language text parser

Could you please conduct code review for the code below and suggest some improvements? Functional specification Implement a multithreading parser based on existing natural language tokenizer. Parser ...
1 vote
2 answers
90 views

Static media gallery generator with python 3.12

The main concern is the hard requirement for python3.12 since I couldn't find a clean replacement for pathlib.Path.relative_to(root, walk_up=True) in earlier ...
0 votes
2 answers
146 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 ...
7 votes
4 answers
1k views

Bubble sort in parallel

I have done bubble sort algorithm on a vector that is filled with randomly generated values. Bubble sort is actually done with the odd-even transposition method: ...
1 vote
0 answers
62 views

Lockless synchronized access to ConditionalWeakTable

I am inexperienced with writing multithreaded applications, and I am trying to wrap a ConditionalWeakTable (CWT) for use as a generalized container type. I'm aware ...
0 votes
1 answer
99 views

decorator for an Executor that allows to get a List of running tasks

As stated in the javadoc below, this is intended for monitoring and debugging. I've found it especially useful for figuring out which tasks got stuck and prevented clean terminations of my ...
5 votes
2 answers
2k views

Asynchronous Server Sockets - Thread-Safety/Performance (MMO Gaming)

I'm writing this game server for my small 2D MMO game. So here are my questions: What do you think about the Thread-Safety of the code? Please explain how can it be made thread-safe / show example/ ...
3 votes
1 answer
101 views

simple multi-threaded TCP chatroom in Java

I'm fairly new at coding and looking to improve. Down below is all of my files for a TCP chatroom with a GUI in java. This is my first networking project so I'm sure it has many problems and does not ...
2 votes
2 answers
218 views

Circular Queue Producer Consumer with Mutex and Condition Variable vs. Sempahore

How can I optimize the performance of the code below? Destruction of the condition variable at the end of main blocks, not sure why this behavior is occurring. Is it possible to remove some of the ...
1 vote
1 answer
203 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): ...
1 vote
1 answer
479 views

Canvas in Tkinter app for Conway's Game of Life updates so slowly

This is Conway's Game of Life written in Python and using Tkinter for GUI. Problems are: The "Play" button works so slowly. I can see how the canvas is redrawing from top to bottom. But when I ...
2 votes
1 answer
839 views

Efficient parallelization of small tasks

Problem statement: Consider a scenario where a vector of very small tasks, each encapsulated within a class 'Task' with a thread-safe method Task::process(), needs to be efficiently processed in ...
7 votes
1 answer
249 views

Differential Evolution

I have a PR implementing differential evolution. I'm a bit concerned about the implementation and would like some feedback: The class could be a free function. However, there are so many parameters, ...
3 votes
1 answer
153 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 ...
1 vote
2 answers
95 views

Stopping a running thread

I am trying to stop an executing runnable instance after the run method has been called. I have come up with the below approach ...
1 vote
2 answers
404 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
448 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
87 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
386 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....

1
2 3 4 5
33