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
10 votes
0 answers
727 views

Sieve32FastV2 - A fast parallel Sieve of Eratosthenes

I’ve created a much cleaner, better designed version to my parallel sieve. I’ve implemented most of EBrown’s micro-optimizations but also revamped the code on my own (that is not in direct response ...
Rick Davin's user avatar
  • 6,360
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 ...
Loki Astari's user avatar
  • 95.4k
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
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
5 votes
1 answer
143 views

Multithreaded console-based monster battle with earliest-deadline-first scheduler

In working on this answer it occurred to me that it might be interesting to further expand the idea. The game This is an extremely simple (and boring!) text-based game that creates a few monsters ...
Edward's user avatar
  • 66.5k
4 votes
0 answers
2k views

Android APP connect to FTP server in Java

I am attempting to build an Android APP with the ability to connect specified FTP server in Java. The connection operation has been performed in FTPconnection class ...
JimmyHu's user avatar
  • 5,392
3 votes
2 answers
1k views

Platform independant thread pool v2

This is a continuation of this question, v3 can be found here Taking into account the advise given by Loki, an implementation of the threadpool using a ...
Tom Myles's user avatar
  • 432
151 votes
17 answers
20k 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,373
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
  • 20k
12 votes
2 answers
10k views

Efficiently using Apache HttpClient in multithreaded environment

I have a library which is being used by customers and they are passing DataRequest object which has userid, various ...
user1950349's user avatar
11 votes
3 answers
667 views

Multithreaded Mandelbrot Generator Ver 2

Update: Version 3 is here. My first version was an answer I provided to EBrown for his original post titled "Multithreaded Mandelbrot Generator". My answer had many good things in it, but I felt ...
Rick Davin's user avatar
  • 6,360
10 votes
1 answer
2k views

Sieve32Fast - A very fast, memory efficient, multi-threaded Sieve of Eratosthenes

An improved version Sieve32FastV2 is available. The classical solutions for the Sieve of Eratosthenes fall into 2 camps: one uses a bool[], which is fast but very ...
Rick Davin's user avatar
  • 6,360
8 votes
3 answers
384 views

Having full atomicity against all the threads without impacting performance or throughputs

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
arsenal's user avatar
  • 2,167
7 votes
2 answers
1k views

Lock for preventing concurrent access in client data

I am trying to implement lock by which I don't want to have reads from happening whenever I am doing a write. Here is my ClientData class in which I am using ...
arsenal's user avatar
  • 2,167
6 votes
2 answers
3k views

Producer/Consumer implementation

I am using Netty embedded within Grails to process and display incoming SNMP messages. Since Netty 4 doesn't come with a built-in ChannelExecutionHandler I had to ...
Diljot R's user avatar
6 votes
3 answers
3k views

A multi-thread Producer Consumer, where a Consumer has multiple Producers (C++17)

EDID: Thank you very much for your feedback. I updated the code and opened a new post for the updated version. See here. This post is loosely based on A multi-threaded Producer Consumer with C++11. ...
User12547645's user avatar
5 votes
2 answers
488 views

Multi-threaded domain status checking in Java

I'm tinkering with the idea of crafting a search engine in my spare time. More of a learning experience than anything at this point, but still a project. A key aspect of this system is checking ...
ndm13's user avatar
  • 718
5 votes
2 answers
4k 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 ...
Developer Paul's user avatar
5 votes
1 answer
2k views

Linked list node-level locking

I am new to C++ threading library. I would love to get some comments on how to improve this code (if there are possible bugs, I would appreciate that feedback too). In particular, I want to refactor ...
nhtrnm's user avatar
  • 183
3 votes
2 answers
522 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 ...
Dávid Tóth's user avatar
3 votes
2 answers
364 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 ...
Dávid Tóth's user avatar
2 votes
1 answer
1k views

Producer-Consumer in C++ - follow-up

To expand from the changes supplied by the answer of my previous question: ...
T145's user avatar
  • 3,099
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 ...
Damir Tenishev's user avatar
1 vote
1 answer
118 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 ...
Dávid Tóth's user avatar
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
  • 20k
41 votes
1 answer
5k 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.6k
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,829
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
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
  • 533
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
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
  • 56.8k
15 votes
3 answers
4k 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
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
12 votes
2 answers
2k views

Implementation of a lock-free fixed-sized allocator

This question now has a follow-up: Implementation of a lock-free fixed-sized allocator - follow-up - with commented code I've tried implementing a lock-free fixed-size allocator while trying to ...
cr_oag's user avatar
  • 565
11 votes
2 answers
2k views

Command line IRC client

I made this IRC client ages ago in Python, and thought I'd revisit it for Python 3.5 (I'd like to play with asyncio). Before I start, I'd like to have an overall design review about this. Known ...
Dan Oberlam's user avatar
  • 7,814
11 votes
1 answer
2k views

Do not share same socket between two threads at the same time

I have a code in which I am dealing with sockets and I need to make sure that I don't share same socket between two threads. In my below code, I have a background thread which runs every 60 seconds ...
david's user avatar
  • 1,947
11 votes
4 answers
13k views

Clean and well-designed Tic-Tac-Toe game

My design goal was to try and make a "clean" and well-designed Tic-Tac-Toe game but also to try and use concepts and programming constructs that I'm new to. I'm planning to implement an "AI Player" ...
Overly Excessive's user avatar
11 votes
1 answer
7k views

Timer to poll a Delegate

This is a followup to this where I was initially using a single thread and Thread.Sleep() to poll a delegate. I was recommended to use a timer and the ...
Alain's user avatar
  • 472
11 votes
3 answers
12k views

Thread pausing/resuming/canceling with Qt

I have written this code to be able to suspend (or to cancel) a worker executed in a separate thread in Qt. To do it, I have used an instance QWaitCondition and <...
FArcellier's user avatar
10 votes
1 answer
1k views

Follow-up: Timer utilizing std::future

The previous code (as displayed in Timer utilizing std::future) is now: ...
Dieter Lücking's user avatar
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 ...
doug65536's user avatar
  • 533
10 votes
2 answers
30k views

Synchronous and asynchronous behavior for client

I am working on a project in which I am supposed to make synchronous and asynchronous behavior of my client. The customer will call our client with a userId and we ...
david's user avatar
  • 1,947
10 votes
1 answer
51k views

Java multi-thread file server and client

My task was to build a multi-thread file server and a client that can upload or download a named file over sockets. It is assumed that the client will finish after its operation and there is no need ...
chris loughnane's user avatar
10 votes
1 answer
2k views

Platform independant thread pool

v2 of this question is here and v3 is here To get a better understanding of C++11/C++14, I thought I would develop a thread pool, even if it has been done to death! The only dependency outside of ...
Tom Myles's user avatar
  • 432
10 votes
1 answer
54k views

Writing to file in a thread safe manner

I'm writing Stringbuilder to file asynchronously. This code takes control of a file, writes a stream to it and releases it. It deals with requests from asynchronous operations, which may come in at ...
Nathan's user avatar
  • 647
9 votes
2 answers
2k views

Concurrent FIFO in C++11

I have implemented a simple FIFO that can optionally be used by either a single thread or way to pass data between threads. The class is templated with arguments for the types the queue will contain ...
schrödinbug's user avatar
9 votes
3 answers
2k views

Naive lock free work stealing queue

Recently, I read a article about work stealing queue Job System 2.0: Lock-Free Work Stealing – Part 3: Going lock-free, and this is my c++11 naive implementation based on my understand of c++11 ...
benlong's user avatar
  • 203
9 votes
3 answers
2k views

Platform independant thread pool v4

This is a continuation of this question. Following the previous advise, the thread pool now can handle almost all types of input, except for one key form, where the function/functor requires one of ...
Tom Myles's user avatar
  • 432
9 votes
2 answers
9k views

Python Port Scanner

This is only my third Python script. Be brutal with me. Any tips, tricks, best practices, or better usages would be great! ...
asteri's user avatar
  • 4,899
8 votes
3 answers
298 views

Command line based game with players and monsters

I am coding a command line based game with 1 player and 2 monsters. Monster attacks player at specified intervals and player takes input from standard input to attack specific monster. I would like ...
Daemon's user avatar
  • 183