Questions tagged [multithreading]
Use this tag when the program performs its work using multiple concurrent threads of execution.
1,589
questions
150
votes
17
answers
19k
views
Disproving Euler proposition by brute force in C
I wrote a little bit of code to brute force disprove the Euler proposition that states:
$$a^4 + b^4 + c^4 = d^4$$
has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers.
I'm no ...
49
votes
5
answers
15k
views
Thread-Safe and Lock-Free - Queue Implementation
I was trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently.
Would you ...
43
votes
5
answers
7k
views
Parallel sieve of Eratosthenes
For the first time, I tried to use threads by myself in order to implement a parallel sieve of Eratosthenes. The trick is that each time a prime is found, a thread is spawned to eliminate all the ...
40
votes
3
answers
11k
views
Exporting doc types using queues and multithreading
For a while I have been interested in seeing if some tasks work well when split across multiple threads.
On the one project I have been busy with I have been creating a lot of small utility apps, to ...
40
votes
1
answer
4k
views
Recursive shared_mutex implementation
I found myself in need of a Readers-Writer mutex. With C++17 TR2 support not yet available in our compiler, I set out to implement std::shared_mutex so that we have ...
39
votes
2
answers
13k
views
A new approach to multithreading in Excel
Intro
Multithreading tools exist in Excel - often to run macros in multiple instances of Excel, or to convert macros to vbscripts that can run independently. However I've often come across projects ...
37
votes
8
answers
25k
views
Thread Pool C++ Implementation
I have been working on this thread pool for awhile to make it as simple to use as possible. I need some tips on improving performance, and some good ways to test its performance. I was wondering if ...
36
votes
2
answers
6k
views
Asynchronous network callback code
I did not get the job after submitting this piece of work in an interview, but I have no feedback to know what "BAD" things are inside this block of code.
The requirements are:
Connect to the ...
30
votes
3
answers
2k
views
Java method - levels of abstraction
In his Clean Code book, Robert C. Martin states that functions should do only one thing and one should not mix different levels of abstraction. So I started wondering whether the code below meets ...
27
votes
3
answers
4k
views
Network chat app
Applying a lot of unprecedented concepts here, it's a simple chat server capable of handling multiple clients, which are run through JavaFX, and have their individual threads instantiated and handled ...
24
votes
3
answers
12k
views
Synchronous / asynchronous REST client
I have working code with original design, and now I had a slight design change so trying to code review that as well. I already had code review on my original design here.
Original Design:
I am ...
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, ...
22
votes
5
answers
36k
views
A TaskScheduler that always run tasks in a specific thread
The following is an TaskScheduler that always run tasks in a thread it maintains.
When created, a name of the thread was specified. Once you schedule the first task,...
22
votes
2
answers
57k
views
Creating a thread-safe list using a Lock object
Will this code qualify for a truly thread-safe list? It is using the Lock object.
...
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-...
19
votes
5
answers
24k
views
A custom thread-pool/queue class
I wanted a class which executes any number of tasks but only a certain amount at the same time (e.g. to download various internet content and keep the overall download speed at a good level). The ...
18
votes
3
answers
5k
views
Producer/Consumer programs
I am studying mutual exclusion in college, and we just covered the producer/consumer problem. The class does not involve writing code, but I decided to implement a bounded buffer version of this ...
18
votes
2
answers
28k
views
Portable periodic/one-shot timer implementation
Note: I have posted a follow-up question for a significantly updated version of this code.
I have implemented a class that provides portable one-shot or periodic timers.
The API provides a way to ...
17
votes
2
answers
6k
views
Lock-free zero-copy triple buffer
In a producer-consumer scenario sometimes we have to deal with the producer being much faster than consumer. The data loss is unavoidable, and we are OK with it, as long as the consumer always has the ...
16
votes
1
answer
6k
views
Summing values in a vector using threads
This is my very first program that using threads. I use C++11 standard threads and I run it on Linux.
The program creates two threads that sums all the elements in a vector together. The first ...
16
votes
2
answers
16k
views
Thread pool on C++11
The class supplies a simple thread pool that uses the thread class from C++11.
When I schedule the job, I pass two std::function<void()> objects that the ...
16
votes
0
answers
3k
views
Realtime concurrent Haskell MIDI buffer
Problem Background
MIDI is a serial representation of control signals to a sound generator. Typically, a noteOn message initiates the attack phase of a sound at a given pitch. The note will ...
15
votes
4
answers
2k
views
Multithreaded Mandelbrot Generator
I built one of these long ago, and it got lost when I reformatted my SSD (sad day) so here is the new version.
It is very multithreaded, spawning numCores - 1 ...
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 ...
15
votes
3
answers
3k
views
Simple HTTP Server
I'm working on a project (studying) and I have a lot of time for proof of concepts and write something from scratch.
Basically I'm creating an HTTP server (simple, but not too simple) in C++ using ...
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.
...
15
votes
4
answers
6k
views
Printing all even and odd numbers with threads
The original question is on careercup.
Write a multi threaded C code with one thread printing all even numbers and the other all odd numbers. The output should always be in sequence
ie. 0,1,2,3,4....
15
votes
5
answers
17k
views
15
votes
1
answer
8k
views
A simple Thread Pool
A very simple Thread pool:
Any work added to the pool will be executed. The destructor will wait for all work to be finished before letting the threads stop. We then join all threads before letting ...
15
votes
2
answers
1k
views
Concurrency limit map in Go
Task: per host concurrency limits for web crawler (map[string]Semaphore).
I considered chan struct{} (chan bool) approach, but ...
15
votes
1
answer
264
views
Delete engine for deeply nested linked structure
The background is the question at https://stackoverflow.com/questions/36634394/nested-shared-ptr-destruction-causes-stack-overflow. To summarize, for a data structure that looks like:
...
15
votes
2
answers
1k
views
Lock-free cache oblivious n-body algorithm
I'm currently looking at, from a rather high level, the parallelization of the gravity calculation in an N-body simulation for approximating a solution to the N-body problem.
The simple form of the ...
15
votes
1
answer
1k
views
C++11 Threadpool
I have developed a threadpool using the standard c++11 features and am looking for feedback.
Right now I think the implementation is pretty solid, but as I recently learned about multithreading I'm ...
15
votes
0
answers
229
views
Download files in parallel
This module has a ensure_downloaded function which takes a slice of Urls. It downloads all of the urls to a local downloads ...
14
votes
2
answers
468
views
Handling game states for an online RPG game
I'm writing an ORPG. The code below is client-side.
I have a main thread looping in Game::Run:
...
14
votes
2
answers
943
views
Mutual Exclusion with Mutexes
After I wrote this question: Producer/Consumer programs, I realized that I had forgotten to write a version using mutexes. I have now solved the Producer/Consumer problem using mutexes and ...
14
votes
2
answers
15k
views
HTTP server and multi-threading optimization
I wrote an HTTP server for the management of scores for users and levels.
It can return the highest score per level. It has a simple login with session-key.
What do you think could be improved in ...
14
votes
3
answers
1k
views
Fetching tweets
I have written this (truncated) code to fetch some tweets:
...
14
votes
2
answers
8k
views
Parallel Merge Sort
Parallism is achieved by using a simple call to tbb::parallel_invoke(). However I can't break a speedup factor of x2 (after ~3-4 parallel HW threads), although 8 ...
14
votes
1
answer
6k
views
Detecting UI thread hanging and logging stacktrace
I have an application that needs to always be responsive. I've written a class that is designed to monitor the UI thread. The goal is to provide useful information in the logs to be able to understand ...
13
votes
3
answers
5k
views
Replacing Skype, reinventing the chat client
I'm creating a chat client and chat server after a several month programming hiatus. The goal is to make one with features I want but it's also a learning project. Although it's mostly because I'm ...
13
votes
5
answers
18k
views
One reader / one writer no-memory-allocation lock-free ring-buffer
I have two threads - one thread queues items another thread dequeues. dequeue is fast enough and so we can assume that queue is never contains more than 65536 items....
13
votes
3
answers
2k
views
Parallel sieve of Eratosthenes, version 2
This question is a revision of Parallel sieve of Eratosthenes. The goal is to implement a sieve of Eratosthenes with parallel strikes out from the boolean array. I tried to fix the data races and all ...
13
votes
2
answers
5k
views
Implementation of a Thread Pool in C++
I wanted to implement a thread pool to test my knowledge of various modern C++ features. The end result could be better, but I need a review as I'm not sure about delicate things especially regarding ...
13
votes
2
answers
322
views
Multi-threaded Command Processor
I have written a class that is intended to execute a unit of work to be run in a separate thread. The intended use case for this class is running business logic off of the user interface thread so as ...
13
votes
1
answer
9k
views
Thread-Safe Integer Sequence
I would like to give an Integer to whatever demands it. For that I use the following code
...
13
votes
2
answers
572
views
Thread-safe large text buffer
This is part of one of my projects called largetext, which actually stemmed from a question on Stack Overflow. The goal is to provide access to a very large text file as a ...
12
votes
5
answers
1k
views
Reducing contention in thread-safe LruCache
I was looking for a in-memory cache class, but couldn't find any in the .Net Core framework; luckily I found one already implemented here.
I made some minor modifications to it and tried to make it ...
12
votes
2
answers
3k
views
Returning the result of whichever method finishes first
Consider a method (let's call it IsPrimeHybrid) which calls at least two methods (let's call them IsPrimeNaive and ...
12
votes
3
answers
9k
views
Concurrent programming with a simple server
I am creating a simple server that accepts a int and returns the value received twice:
...