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
37 votes
3 answers
2k views

Voxel World Optimization

This is not related to a Minecraft clone. I am currently writing a turn-based strategy game like Final Fantasy Tactics. The game is played on floating voxel-style islands, which are generated from ...
Krythic's user avatar
  • 1,488
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
19 votes
2 answers
10k views

Using Java 8 parallel streams

I'm trying to get more familiar with the new Java 8 features, so I am rewriting one of my earlier projects. It includes a class that keeps track of the best entry seen so far: ...
Mangara's user avatar
  • 465
15 votes
1 answer
2k views

Go Go Gadget Web Crawler

In A Tour of Go, you are given the following problem: In this exercise you'll use Go's concurrency features to parallelize a web crawler. Modify the Crawl ...
mjolka's user avatar
  • 16.2k
13 votes
2 answers
568 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
2 answers
182 views

java.util.concurrent bounded resuable resource implementation

I'm trying to code following requirements with lockfree in most-used-code-path that is to get a resource from pool. Same resource should be used n (maxUsageCount) ...
dtoes's user avatar
  • 121
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
12 votes
1 answer
508 views

Concurrency interview

A little while back I had an interview where they posed a problem, in summary: Watch a certain directory, and process incoming JSON files These JSON files have various "Type" fields Every second ...
mjgpy3's user avatar
  • 729
11 votes
2 answers
872 views

Parallelized for loop in Bash

I am using a Bash script to execute a Python script multiple times. In order to speed up the execution, I would like to execute these (independent) processes in parallel. The code below does so: <...
user213544's user avatar
11 votes
2 answers
4k views

TaskScheduler that uses a dedicated thread

I'm trying to implement a TaskScheduler that runs all tasks in the order they are submitted, on a single dedicated thread. Here's my implementation, using a ...
Asik's user avatar
  • 321
11 votes
2 answers
5k 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
11 votes
2 answers
2k views

Thread-safe session manager

Expected behavior of the code below: There will be one static SessionManager accessed by many threads. Multiple calls to ...
Ocelot20's user avatar
  • 1,883
11 votes
2 answers
4k views

How can this simple coroutine implementation be improved?

This is a quick and dirty implementation of coroutines that implements yield by saving and restoring the stack to and from the heap. Here's an earlier version, which does the most naive possible thing,...
dan's user avatar
  • 309
11 votes
2 answers
10k views

Concurrent task processing queue

I can have a maximum of three concurrent threads processing tasks. Each of these threads can process 1 to 100 tasks simultaneously (by connecting to an external system). The time taken to process 100 ...
jimjim's user avatar
  • 211
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
10 votes
4 answers
8k views

AsyncDictionary - Can you break thread safety?

This class is an Async/Await wrapped Dictionary. Of course it doesn't technically implement IDictionary, but the functionality is basically the same as an IDictionary. It achieves similar ...
Christian Findlay's user avatar
10 votes
4 answers
4k views

Send email just once per day

I want to send an email just once per day. There is one button and any user can click that button. The email must not be sent twice. When the first user clicks the button, the email is sent. If ...
Raskolnikov's user avatar
10 votes
4 answers
9k views

Concurrent multi-server pinging in Java

I have an application that essentially "pings" all of the servers on my network. I have about 100 servers, and this ping will happen every 10 seconds. ...
user872129's user avatar
10 votes
2 answers
1k views

Naive parallel Sieve of Eratosthenes in Java

My naive version now is too slow. I think setting/accessing concurrent atomic bit is way slower compared to access/modify an array of boolean. Second, the parallel execution only happens on the ...
rdllopes's user avatar
  • 868
10 votes
2 answers
2k views

Threadsafe HashMap with snapshot support

The problem ConcurrentHashMap provides very weak consistency guarantees w.r.t iteration: guaranteed to traverse elements as they existed upon construction exactly once, and may (but are not ...
radai's user avatar
  • 258
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.3k
10 votes
2 answers
552 views

RAII pattern for downgradable ReadWriteLock

The example for downgrading ReentrantReadWriteLock in the Java documentation seems really unsafe when handling exceptions. I tried to write a simple class to ...
Juan Lopes's user avatar
10 votes
1 answer
1k views

"Barbershop"-esque Semaphore Implementation

Recently, I submitted a project that simulates a barbershop-style problem; the task was to create a Hotel that contained guests, front-desk employees, and bellhops. ...
Evan Bechtol's user avatar
  • 1,255
10 votes
1 answer
113 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.3k
10 votes
1 answer
157 views

Simple concurrency implemented in Python

Purpose of the question: learn more about ways to implement concurrency in Python / experimenting. Context: I want to count all of the words in all of the files that match a particular pattern. The ...
Michael's user avatar
  • 285
10 votes
1 answer
440 views

ConcurrentDecayingHashMap<K,V>, a concurrent decaying HashMap

I wrote a wrapper for Java's ConcurrentHashMap that enables you to add a decay time to inserted values, meaning they will be automatically removed after the given ...
ASA's user avatar
  • 473
9 votes
1 answer
11k views

Printing even and odd using two concurrent threads

Please review the code below where thread Odd prints all odd numbers from 1 to 9 and thread Even prints all even numbers from 2 to 8. I tested it and it works but can we improve it from design or ...
real gadha's user avatar
9 votes
2 answers
1k views

C++11 Blocking connection pool with auto release

Relatively new to C++. Please help me understand the potential issues with the following blocking object pool. ...
271828183's user avatar
  • 189
9 votes
1 answer
1k views

Dynamically extensible threadpool implementation in C

Purpose For my recent project, I needed a thread pool. I saw a lot of implementations at GitHub, but most of them were quite complicated. With complication comes performance penalty. Most importantly,...
Subhranil's user avatar
  • 191
9 votes
1 answer
5k views

Continuation Implementation in C++11

While playing with the concurrency features in C++11 I noticed that there wasn't any support for continuations. I wanted to develop something similar to Tasks in The Parallel Patterns Library (PPL), ...
Eóin Ó'Flynn's user avatar
8 votes
3 answers
22k views

Mutex implementation

Overarching Problem I am creating a threadsafe queue that will act as a shared buffer between two threads for a game I am developing. I need it to be threadsafe so that one thread can throw messages ...
Dean Knight's user avatar
8 votes
3 answers
2k views

The dumbest (futex-based) mutex

After reading Ulrich Drepper's "Futexes are Tricky", I have written the following "dumbest mutex" in C++14 using the Linux futex primitives. This mutex is simpler ...
Quuxplusone's user avatar
  • 19.3k
8 votes
2 answers
427 views

Concurrent Task Waiter 2

This is an iteration of my previous question: Concurrent Task Waiter Summary from before: I have some code designed to simplify managing multiple asynchronous operations. The code creates ...
Nick Udell's user avatar
  • 5,187
8 votes
2 answers
371 views

Is this a good way of managing parallel go routines when I care about ordering of results?

I have a process with a number of stages that need to be completed in sequence. Each stage is largely parallelisable, involving looping over a large data structure and processing each item ...
Nat's user avatar
  • 1,016
8 votes
2 answers
43k views

Wait until all files are loaded asynchronously, then run code

I'm an experienced programmer but not too great at JavaScript so I'm looking to see if I'm doing this 'right'. I want to have several files loaded in (Ajax or really AJAJ) and, once loaded, run some ...
Charles's user avatar
  • 509
8 votes
1 answer
474 views

Cache<Long, BlockingDeque<Peer>> combined with Striped<ReadWriteLock>: is it thread-safe

I've implemented PeersContainer class with all operations that I need. I need something like multimap in concurrent environment, moreover I need remove entities ...
VB_'s user avatar
  • 237
8 votes
2 answers
6k views

Concurrent observable collection

I'm working on a WPF 4.5 desktop application that has several nested collections with the following key aspects: writes mainly from UI thread, but also from worker threads writes are relatively ...
mike's user avatar
  • 181
8 votes
1 answer
3k views

A non-blocking lock decorator in Python

I needed to impose on a Python method the following locking semantics: the method can only be run by one thread at a time. If thread B tries to run the method while it is already being run by thread A,...
bdesham's user avatar
  • 225
8 votes
1 answer
1k views

Constant keys thread safe dictionary

I find that I use this pattern a lot where I have a dictionary which I would only read from and update and wouldn't add/remove keys. In that case, using ...
Arik's user avatar
  • 191
8 votes
3 answers
31k views

Dining philosophers problem with mutexes

I know this dining philosophers problem has been researched a lot and there are resources everywhere. But I wrote simple code to solve this problem with C and then turned to the Internet to see if it'...
Pramod Herath's user avatar
8 votes
1 answer
4k views

Custom TCP Java proxy socket load balancer

I'm working on implementing a custom TCP proxy server which acts like a load balancer. The proxy server will accept client requests and then forward them to available hosts. I am concerned about the ...
Sam Hams's user avatar
  • 181
8 votes
1 answer
2k views

Reading one source Stream by multiple consumers asynchronously

The problem was using single Stream from the HTTP response in multiple consumers simultaneously. For example: while data is loading, I want write it to the some ...
aepot's user avatar
  • 1,989
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
8 votes
0 answers
304 views

Implementing GSL synchronized_value

Core Guidelines mention a type synchronized_value<T>, which supposedly pairs std::mutex with the internal value. I couldn'...
Sergey Kolesnik's user avatar
7 votes
4 answers
1k views

Caching Color-Bitmaps as MemoryStreams

I am in the need to cache Bitmap's in a memory-optimized way because the API I am building will need to process many colored ...
Heslacher's user avatar
  • 50.3k
7 votes
2 answers
5k views

Queue for distributing tasks between threads

I implemented the following class to dispatch std::function<void(void)> objects to a thread pool. Multiple threads will block on the pop call until a task is ...
Richard's user avatar
  • 193
7 votes
2 answers
4k views

Concurrent Linked Hash Set

Basically I want to create a concurrent LinkedHashSet which returns proper size too. I am mainly concerned about adding and removing iterations. Suggestions ...
Abhishek Bhatia's user avatar
7 votes
3 answers
3k views

Concurrent HTTP request loop

I'm using the rolling curl library to fire HTTP requests for content-length headers of images (we need to know their size to weed out placeholders and low res images). The image URLs are stored in a ...
codecowboy's user avatar
7 votes
1 answer
877 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
  • 27k
7 votes
1 answer
7k views

RabbitMQ wrapper to work in a concurrent environment

I'm developing a common library for my organisation that will be used across different services by different teams. The library is a simple wrapper for RabbitMQ. Some services will only be producers, ...
Brian Pilgren's user avatar

1
2 3 4 5
10