Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
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 ...
Aidenhjj's user avatar
  • 2,363
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 ...
Hosam Aly's user avatar
  • 1,301
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 ...
Morwenn's user avatar
  • 19.9k
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 ...
JonathanPeel's user avatar
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 ...
Emily L.'s user avatar
  • 16.5k
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 ...
Greedo's user avatar
  • 2,345
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 ...
Paul's user avatar
  • 492
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 ...
TheOneTeam's user avatar
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 ...
cafe_'s user avatar
  • 465
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 ...
Legato's user avatar
  • 9,819
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 ...
david's user avatar
  • 1,647
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, ...
Ash's user avatar
  • 364
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,...
Earth Engine's user avatar
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. ...
Mrinal Kamboj's user avatar
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-...
Mast's user avatar
  • 13.1k
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 ...
H.B.'s user avatar
  • 335
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 ...
user avatar
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 ...
doug65536's user avatar
  • 513
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 ...
vnp's user avatar
  • 55.9k
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 ...
Bojack's user avatar
  • 437
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 ...
Paolo Brandoli's user avatar
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 ...
user1441998's user avatar
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 ...
Der Kommissar's user avatar
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 ...
Incomputable's user avatar
  • 9,374
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 ...
Radagast's user avatar
  • 295
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. ...
JohnScott's user avatar
  • 171
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....
Hui Zhao's user avatar
  • 253
15 votes
5 answers
17k views

Java blocking queue

...
a3user's user avatar
  • 151
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 ...
Martin York's user avatar
  • 94.3k
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 ...
temoto's user avatar
  • 251
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: ...
Zizheng Tai's user avatar
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 ...
Mike Bailey's user avatar
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 ...
amc176's user avatar
  • 345
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 ...
Winston Ewert's user avatar
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: ...
Mislav Blažević's user avatar
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 ...
user avatar
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 ...
user1883212's user avatar
14 votes
3 answers
1k views

Fetching tweets

I have written this (truncated) code to fetch some tweets: ...
user avatar
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 ...
inf's user avatar
  • 564
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 ...
Brian Flynn's user avatar
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 ...
OkeWoke's user avatar
  • 133
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....
Oleg Vazhnev's user avatar
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 ...
Morwenn's user avatar
  • 19.9k
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 ...
KeyC0de's user avatar
  • 233
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 ...
Cypher's user avatar
  • 231
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 ...
Manuelarte's user avatar
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 ...
fge's user avatar
  • 1,743
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 ...
Trauer's user avatar
  • 801
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 ...
Theodoros Chatzigiannakis's user avatar
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: ...
Rex's user avatar
  • 123

1
2 3 4 5
32