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
2answers
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 ...
5
votes
3answers
2k 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. ...
5
votes
1answer
979 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 ...
4
votes
1answer
4k 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. ...
3
votes
1answer
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 ...
6
votes
4answers
10k 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 ...
33
votes
2answers
66k 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? ...
6
votes
3answers
327 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 ...
7
votes
1answer
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. ...
5
votes
1answer
528 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: ...
4
votes
2answers
20k 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 ...
3
votes
4answers
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 ...
12
votes
2answers
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 ...
7
votes
2answers
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 ...
3
votes
4answers
21k 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. ...
10
votes
2answers
117 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: ...
9
votes
2answers
3k 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 ...
8
votes
1answer
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 ...
7
votes
1answer
824 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 ...
6
votes
3answers
185 views

Thread-safe retirement account class

Are these classes properly guarded for thread safety? Do you see any issues with any of the classes? ...
6
votes
1answer
666 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-...
5
votes
3answers
1k views

Golang Tour Webcrawler exercise

I am new in Go and for study I have to hold a presentation about concurrency in Go. I think the Golang Tour - Webcrawler exercise is a nice example to talk about that. Before I do that, it would be ...
5
votes
1answer
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 ...
1
vote
1answer
460 views

Concurrent Task Waiter

I have some code designed to simplify managing multiple asynchronous operations. The code creates callback actions that, when executed by the asynchronous operation, track which asynchronous methods ...
1
vote
0answers
72 views

Wikipath stack in Java - Part I/IV - The search algorithm

I am working on the following small software stack: The objective of the entire stack is to search for shortest paths in the Wikipedia article graph as fast as possible. As of now, I rely on two ...
11
votes
1answer
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 ...
10
votes
1answer
109 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 ...
7
votes
1answer
872 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 ...
6
votes
2answers
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 ...
5
votes
2answers
77 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 ...
4
votes
2answers
2k 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 ...
4
votes
1answer
183 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 ...
3
votes
1answer
774 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. ...
3
votes
2answers
125 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.: ...
3
votes
1answer
266 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 ...
3
votes
2answers
198 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 ...
2
votes
1answer
5k 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 ...
2
votes
1answer
9k 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; ...
2
votes
1answer
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 ...
2
votes
1answer
1k 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 ...
2
votes
1answer
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?...
2
votes
0answers
786 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 ...
1
vote
1answer
63 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 ...
1
vote
1answer
616 views

Find pairs of consecutive numbers fetched from blocking queues

I was coding for the following programming question: Suppose you have two independent blocking queues that will keep getting new data, the new data will always be greater than the last element of ...
1
vote
2answers
116 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 ...
1
vote
1answer
580 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. ...
1
vote
1answer
543 views

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

This post is based on A multi-thread Producer Consumer, where a Consumer has multiple Producers (C++17). I am trying to build a Consumer that consumes data from ...
0
votes
0answers
150 views

Pause & Resume producer

Following code produces number sequentially. There will be only one such producer, However there can be many threads to pause/resume the list of sequential numbers. ...
0
votes
1answer
114 views

A portable parallel loop construct in C89 - follow-up

This is a follow-up question to A portable parallel loop construct in C89. I have incorporated all the good points made by vnp. Now my code looks like this: parallel_for.h ...
0
votes
3answers
1k views

Implementing multiple Producer Consumer using custom Blocking queue [closed]

I am trying to implement multiple producer multiple consumer problem using a custom blocking queue. The requirement is that: If the queue is not full, all the producers should be able to produce ...