As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [concurrency]

In computer science, concurrency is a property of systems in which multiple computations can be performed in overlapping time periods. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.

Filter by
Sorted by
Tagged with
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
4 answers
11k views

Implemenation for concurrent file access (read/write)

I am developing an application that works with files and folder on a network share (similar to the windows explorer). The application is used by multiple users and provides some commands for modifying ...
JanDotNet's user avatar
  • 8,528
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
1 answer
993 views

Python Port Scanner 2.0

A few months ago I put up a port scanner for review. Now, I've updated it with some new Python knowledge and integraing the feedback I got. Some things I specifically think might be wrong with it or ...
asteri's user avatar
  • 4,869
5 votes
2 answers
2k 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
4 votes
1 answer
5k views

Concurrent/parallel ForEachAsync - proper handling of exceptions and cancellations

I've created an asynchronous parallel ForEach mechanism so I could enumerate an enumerable by N degrees of concurrency and process an action for each item. ...
Terry's user avatar
  • 219
3 votes
1 answer
3k views

Creating a concurrent/parallel ForEachAsync that can fail immediately or wait until enumeration is complete

I needed an asynchronous parallel ForEach mechanism so I could enumerate an enumerable by N degrees of concurrency and process an action for each item. Searching ...
Terry's user avatar
  • 219
34 votes
2 answers
68k views

A multi-threaded Producer Consumer with C++11

I am trying to learn concurrent programming in C++11. I tried to write code for a classic producer consumer concurrency problem. Would you please review and make any comments about it? ...
Robomatt's user avatar
  • 391
12 votes
2 answers
2k views

Python Port Scanner 2.1

I made lots of changes to the script presented in my previous question. I was tempted to edit that one with the new code, but it would invalidate @200_success's helpful answer. It was also ...
asteri's user avatar
  • 4,869
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,647
11 votes
2 answers
4k views

Multi Threaded High Performance txt file parsing

EDIT A port of Björn's answer to C++ with further improvements at bottom achieving up to 2.4GB/s on the reference machine. Text file parsing and processing continues to be a common task. Often it's ...
Oliver Schönrock's user avatar
10 votes
1 answer
112 views

Shady Characters

As part of my familiarization with the features of Java 8, and inspired by this question, I thought I would take the 'Shady Character' problem to 'the next level'. The basic problem is that you have ...
rolfl's user avatar
  • 97.2k
10 votes
2 answers
120 views

Poke-a-Dot (Provider)

I need to create variable-length strings of dots/periods/full-stops to add to some text content, in a way that is similar to a formatted table-of-contents: ...
rolfl's user avatar
  • 97.2k
8 votes
1 answer
5k views

Generic Java task-scheduler

I wrote this generic task scheduler for executing tasks in fixed-delay intervals. Can you find anything wrong with it, or issues that may arise from using it for sending something like queued mails in ...
epoch's user avatar
  • 183
7 votes
1 answer
9k views

Concurrent LRU cache using sychronizedMap() or ReadWriteLock

Trying to implement a simple, thread-safe LRU cache that's meant for "read mostly" use. Collections.sychronizedMap() Clean, simple, not much else to say. ...
raffian's user avatar
  • 173
7 votes
3 answers
849 views

Lock-free multi-producer / multi-consumer queue in C++

I've been working on a lockless multi-producer, multi-consumer queue in an effort to learn as much as I can about concurrency, without the use of mutual exclusion. The queue uses a bounded ring buffer ...
Primrose's user avatar
7 votes
1 answer
934 views

Sorting Algorithm Visualizer

Over the course of the past month I've worked on a little visualizer to show how different algorithms are sorted. I'm pretty happy with how it turned out but would be interested in any feedback ...
MattDs17's user avatar
  • 225
7 votes
1 answer
866 views

A portable parallel loop construct in C89

(There is a next iteration available.) I was practicing writing some portable C89 code and came up with this parallel for loop construct. Basically, if you have a ...
coderodde's user avatar
  • 26.7k
7 votes
2 answers
7k views

Solving a race condition

In my application, I have a message dispatcher. Each message gets relayed to a dispatcher thread. In some scenarios, I can get two responses from the third party in the same millisecond: An "I ...
durron597's user avatar
  • 918
6 votes
3 answers
339 views

URLEncoder implementation

I'm looking for feedback on my URLEncoder implementation, which is a drop-in replacement for Apache Tomcat's URLEncoder. It was ...
Svetlin Zarev's user avatar
6 votes
1 answer
684 views

General Batched Job Runner

This question is inspired by: Generic Task Scheduler where the problem is to run tasks on a scheduled basis, in parallel, and have individual timeouts for each job. For example, consider this use-...
rolfl's user avatar
  • 97.2k
6 votes
3 answers
189 views

Thread-safe retirement account class

Are these classes properly guarded for thread safety? Do you see any issues with any of the classes? ...
user2066049's user avatar
6 votes
2 answers
3k views

Canonical Implementation for a Concurrent Subclass of NSOperation in Swift 2

I would like to develop a kind of template or canonical implementation for a concurrent subclass of NSOperation in Swift. See here for my previous request which is implemented in Objective-C. In that ...
CouchDeveloper's user avatar
5 votes
3 answers
882 views

Single Producer Single Consumer lockless ring buffer implementation

I am writing a simple ring buffer for my own education. Below is a crack at a strategy described in http://www.cse.cuhk.edu.hk/~pclee/www/pubs/ancs09poster.pdf : Producer and Consumer keep local ...
samwise's user avatar
  • 59
5 votes
1 answer
2k views

Hybrid Lock Implementation

I have an algorithm that is painfully slow if I use 'pure' mutexes. That's because most of the critical sections are short and far shorter than the work to sleep a thread. However, it is also slower ...
user avatar
5 votes
2 answers
3k views

Parallel for loop in Java 8

This is my first attempt to provide some syntactic sugar for doing mutually independent loop iterations in parallel. Thanks to Java 8 lambdas, I can write the parallel loops in pretty elegant fashion ...
coderodde's user avatar
  • 26.7k
5 votes
1 answer
674 views

Concurrent for loop in C++

(See the next iteration.) I have this easy to use facility that maps input elements to output elements concurrently by the means of a thread pool: concurrent.h: ...
coderodde's user avatar
  • 26.7k
5 votes
2 answers
82 views

Class to manage updates coming in from another thread

Managing updates from other threads into Swing is a hard problem. In MVC design, if you don't want to have the Presenter be responsible for Thread safety, you can end up with deadlock issues, and also ...
durron597's user avatar
  • 918
4 votes
1 answer
2k views

Debounce and throttle tasks using Swift Concurrency

There are many debouncer and throttle implementations created using Grand Central Dispatch, and even one built into Combine. I ...
TruMan1's user avatar
  • 123
4 votes
1 answer
236 views

Golang HTTPS certificate expiry checking CLI tool

I am a beginner at using Golang, I would like advice about the following program. It is a CLI tool that can check the expiration dates of HTTPS certificates concurrently. I have only used the standard ...
preetpalS's user avatar
4 votes
2 answers
717 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 ...
Developer Paul's user avatar
4 votes
1 answer
191 views

Copying into two different folders on a machine simultaneously

I am trying to copy files from machineB and machineC into machineA as I am running my shell ...
arsenal's user avatar
  • 2,167
4 votes
4 answers
5k views

C++11 Blocking Queue learning exercise

As part of my own C++11 learning exercise I have implemented this Blocking Queue using the new C++11 thread API. One of the aspects I would like to improve is efficiency i.e. in the ...
SkyWalker's user avatar
  • 141
4 votes
2 answers
22k views

Parallel Task Queue that runs in sequence

I'm in need of a solution that runs constantly incoming requests in a per-resource sequence, but parallel in general. The use-case: Many clients connect to a server and start issuing work. The work ...
Vengarioth's user avatar
3 votes
4 answers
23k views

Reader-writers problem using semaphores in Java

I have written my own solution to the Reader-Writers problems using semaphores based on the psuedocode from Wikipedia. I would like to gauge the correctness and quality of the code. ...
tsaebeht's user avatar
  • 141
3 votes
1 answer
795 views

Optimizing code using semaphore to control Netty channel pool

I am using Netty to exchange messages between a client and server. For this, I am maintaining a channel pool on client side. Please help me in optimizing this code. ...
gladiator's user avatar
  • 153
3 votes
2 answers
223 views

Concurrent for loop in C++ - follow-up

I have incorporated all the cool points made by ChrisWue in the initial iteration of this post. Now, I am not reinventing the wheel for my concurrent queue, but use internally ...
coderodde's user avatar
  • 26.7k
3 votes
1 answer
2k views

Concurrent fire and forget async task queue

I had to do a lot of IO stuff on my server running Node JS where I did not really care about the result of the operations. The list of incoming tasks could be huge, so I had to limit the number of ...
Endauriel's user avatar
  • 153
3 votes
1 answer
273 views

Managing socket pool per datacenter

I have a list of sockets per datacenter (in general, I have around three datacenter and each datacenter having 20 sockets, so in total I have around 60 sockets). Now I have 20 business threads which ...
david's user avatar
  • 1,647
2 votes
2 answers
514 views

Blocking call to an async function

While migrating to structured concurrency it may be sometimes convenient to temporarily make a blocking call to an async function - e.g.: ...
Milos's user avatar
  • 609
2 votes
1 answer
1k views

Ensuring no race conditions in my concurrent/parallel ForEachAsync method

Hopefully the final chapter of my ForEachAsync code review. The original question was the starting point and the second question contained modifications suggested ...
Terry's user avatar
  • 219
2 votes
1 answer
6k views

Send data on a socket from multiple threads

I have around 60 sockets, 20 business threads and 1 pinger timer thread and I want to make sure each of those thread works on different socket every time so I don't want to share same socket between ...
david's user avatar
  • 1,647
2 votes
1 answer
994 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 ...
Developer Paul's user avatar
2 votes
0 answers
972 views

Many-readers-one-writer with semaphores and multithreading

I've been looking for a solution to the may readers one writer in Java. I was intrigued by this question posted here and I read the Wikipedia entry about it. So far, I've reached a fine solution, or ...
Oscar Besga Panel's user avatar
2 votes
1 answer
10k views

Parallel for loop in Java 8 - follow-up

The previous and initial iteration at Parallel for loop in Java 8. Changes are as follows: ParallelLoopBody removed; ...
coderodde's user avatar
  • 26.7k
2 votes
1 answer
1k views

Optimizing code using semaphore to control Netty channel pool - Part 2

Please have a look at my original question: Optimizing code using semaphore to control Netty channel pool I have made some changes as pointed out by @rolfl The new code is as follows. Is this better?...
gladiator's user avatar
  • 153
1 vote
1 answer
174 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 ...
noes's user avatar
  • 43
1 vote
0 answers
98 views

Golang HTTPS certificate expiry checking CLI tool (UPDATED)

I previously submitted this CLI tool to this site for review and have made changes based on comments by the reviewer. I have refactored the code, fixed a bug (the tool will no longer output ...
preetpalS's user avatar
1 vote
2 answers
125 views

Threadsafe filtering queue

I have implemented a thread safe filtering queue. The queue allows any objects, of the specified type to be added. A thread interested to take an object must specify which object it is interested in ...
Bruno Costa's user avatar
  • 5,556
1 vote
1 answer
601 views

Concurrent blocking stack

I just want to train before interview. I googled concurrency interview questions and one of the question was write concurrent ready stack. ...
gstackoverflow's user avatar