Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [multithreading]

Multi-threading is how work performed by a computer can be divided into multiple concurrent streams of execution (generally referred to as threads).

Filter by
Sorted by
Tagged with
0 votes
0 answers
11 views

Using Kotlin coroutines, is this the proper way to schedule a task whose result you don't care about inside a suspend function? [closed]

I'm kind of trying to simulate getting cached stuff from some cache and then update the UI and the cache with a webservice call. I'm wondering if this "skeleton" of doing it is fine. Is it ...
user avatar
2 votes
1 answer
54 views

Multithreaded tcp server accepting two clients with task factory and graceful shutdown

as an exercise from multithreading and networking I have decided to create my own implementation of TCP server accepting connections from two clients (which is I think a pretty common case e.g. chess ...
user avatar
  • 23
1 vote
0 answers
65 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 ...
user avatar
  • 111
2 votes
1 answer
56 views

C++20 Multi-queue Thread Pool with Work Stealing

This is a follow up to my previous post which also follows up on my first post regarding my thread pool implementation. I have since made some further changes and attempted to improve performance with ...
user avatar
1 vote
0 answers
142 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 ...
user avatar
  • 169
4 votes
2 answers
80 views

Multi-threaded Mandelbrot set generator slower than single thread

I am new to parallel programming. I have been playing around with multi-threading and for some reason, multi-threading the Mandelbrot set is slower than running a single thread. I have been trying to ...
user avatar
1 vote
1 answer
53 views

Do I really need to re-interrupt a thread doing end-of-life tasks on interruption?

Before showing-off the code, here is a bit of an explanation. I have a Spring component that spawns a thread for watching a directory for new files. In this context, I have a method that runs in a ...
user avatar
1 vote
0 answers
16 views

TCP socket management using multiprocessing

I wrote a Python code for a device that generates an hotspot and communicates with an app using a TCP socket. The communication is managed by a process that opens a socket and uses two threads to send ...
user avatar
  • 111
8 votes
2 answers
588 views

Multithreaded bogosort in Rust

For some quick context, I'm fairly new to Rust and decided to give myself a difficult-but-attainable task of implementing a sorting algorithm. I chose bogosort (or stupid-sort, shuffle-sort, whatever ...
user avatar
0 votes
0 answers
27 views

Python scraper that gets product information from e-commerce website

I have built a scraper that scrapes data from e-commerce website and saves it to json using my own module. Although, I made the scraper multi-threaded, it starts slow, then speeds up and uses a lot of ...
user avatar
2 votes
1 answer
68 views

tiny thread pool implementation

I wanted to write a minimal thread pool implementation. You can submit tasks and get a future. When the pool goes out of scope, all pending tasks will complete and join all workers. In an earlier ...
user avatar
  • 133
1 vote
1 answer
68 views

Low-Latency Multithreaded Logger

My goal was to have a logger that does the blocking file I/O in a separate thread. A few notes: I made it a singleton rather than having a global "logger" variable, or a bunch of loggers ...
user avatar
1 vote
1 answer
71 views

multiply matrices

I wrote a program that calculates the multiplication of two matrices (of compatible dimensions) where each element of the resulting matrix is ​​calculated by a separate thread. Each thread calculates ...
user avatar
  • 1
0 votes
0 answers
37 views

Find shortest route through a maze

The above parallelize code is taking much more time as compare to the original one. I have used bfs approach to solve the problem. I am getting the correct output but it is taking too much time. (x, y)...
user avatar
3 votes
2 answers
116 views

C++ thread pool and thread safe queue

This is my first time writing a custom thread pool in C++. I would love some feedback on how my code looks and if I am missing best practices or have glaring/subtle issues. Thanks! ThreadPool.hpp: <...
user avatar
1 vote
1 answer
39 views

Re-usable worker pool classes

I am trying to read multiple files in parallel in such a way so that each go routine that is reading a file write its data to that channel, then have a single go-routine that listens to that channel ...
user avatar
  • 169
15 votes
2 answers
1k views

A multithreaded implementation of the 'which' command

Here is an implementation of the 'which' command which can tell where programs are located. ...
user avatar
  • 161
1 vote
1 answer
100 views

Collect and combine results of async calls returning completable futures in Java in a cleaner way?

I need an abstract way to implement this below functionality because in my code I have to use it in multiple places with different REST endpoints. If I ignore it will cause code duplication. Please ...
user avatar
6 votes
0 answers
106 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 ...
user avatar
4 votes
2 answers
141 views

C++20 Single Queue Thread Pool

This is a follow up to my previous post. I've made a number of improvements to the thread pool and corrected some bugs as well. The most up to date version of the code is available on my Github. I ...
user avatar
4 votes
1 answer
117 views

Simple parallel compression using Run-length Encoding in C

I encountered the concurrency-zip project in OSTEP By Remzi Arpaci-Dusseau. So basically, I've built a simple compression program that uses Run-length Encoding, and multi-threading in C. But I couldn'...
user avatar
2 votes
0 answers
64 views

C++ logger for Windows

I have written a simple logger in C++ on Windows that I want to use to log info and errors from multiple threads to DbgView: ...
user avatar
  • 255
2 votes
1 answer
93 views

Least Recently Used Cache with TTL

I found this problem in a book and found it interesting. wrote this class to implement a Least Recently Used Cache with TTL. Goal - LRU cache with TTL Multithreaded. Functions: Get(key), Put(key,...
user avatar
7 votes
2 answers
1k views

C++ Thread safe priority queue implementation

My first attempt at writing a thread safe priority_queue. It is not the most efficient because the locks can be even more fine grained if I add implementation of heap instead of using priority_queue ...
user avatar
1 vote
1 answer
68 views

Bank account concurrency problem Swift

I tried to implement a simple BankAccount class to practice providing a solution to the common Bank Account transaction data race problem. Reference to a description of such a problem can be found ...
user avatar
  • 165
2 votes
1 answer
83 views

C++14 Lock-free Multi-producer, Multi-Consumer Queue

Introduction This is a follow-up to a previous question of mine, where I presented another queue of the same type to get some feedback on it. Some people pointed out some fundamental errors I had ...
user avatar
4 votes
1 answer
98 views

Task manager object for lazy initialization

The Problem I am developing a Visual Studio extension for importing code from a server. Because of the way Visual Studio works, multiple threads could try to perform the same operation at the same ...
user avatar
14 votes
2 answers
1k 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 ...
user avatar
  • 9,089
3 votes
1 answer
70 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? ...
user avatar
0 votes
1 answer
43 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 ...
user avatar
1 vote
1 answer
41 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 ...
user avatar
1 vote
1 answer
35 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 ...
user avatar
1 vote
1 answer
44 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 ...
user avatar
4 votes
1 answer
113 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 ...
user avatar
  • 411
1 vote
2 answers
200 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 <...
user avatar
0 votes
1 answer
41 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 ...
user avatar
  • 161
5 votes
1 answer
161 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 ...
user avatar
  • 161
1 vote
2 answers
52 views

Replacement for starting threads from a for loop

I have the following code: ...
user avatar
2 votes
0 answers
192 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, ...
user avatar
  • 171
0 votes
0 answers
36 views

await for multiple timed blocking operations

Inspired by SO questions (1, 2) about joining multiple threads with timeout, I've created a small utility to await for any type of timed blocking operations (like ...
user avatar
  • 141
1 vote
1 answer
76 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 ...
user avatar
  • 161
10 votes
2 answers
1k 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. ...
user avatar
2 votes
2 answers
512 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. ...
user avatar
5 votes
2 answers
873 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 ...
user avatar
2 votes
0 answers
215 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 ...
user avatar
  • 317
3 votes
1 answer
154 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. ...
user avatar
  • 771
3 votes
2 answers
113 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 ...
user avatar
  • 265
3 votes
2 answers
126 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 ...
user avatar
  • 43
1 vote
1 answer
75 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 ...
user avatar
  • 43
1 vote
1 answer
317 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 ...
user avatar
  • 11

1
2 3 4 5
32