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
3answers
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 ...
31
votes
2answers
62k 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? ...
19
votes
2answers
9k 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: ...
15
votes
1answer
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 ...
13
votes
2answers
494 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 ...
12
votes
2answers
175 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) ...
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 ...
12
votes
1answer
455 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 ...
11
votes
2answers
555 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: <...
11
votes
2answers
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 ...
11
votes
2answers
3k 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,...
11
votes
2answers
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 ...
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
4answers
3k 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 ...
10
votes
4answers
3k 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 ...
10
votes
4answers
8k 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. ...
10
votes
2answers
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 ...
10
votes
2answers
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 ...
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: ...
10
votes
2answers
465 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 ...
10
votes
1answer
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. ...
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 ...
10
votes
1answer
118 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 ...
10
votes
1answer
368 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 ...
9
votes
1answer
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 ...
9
votes
2answers
3k 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 ...
9
votes
2answers
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. ...
9
votes
1answer
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), ...
8
votes
3answers
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 ...
8
votes
2answers
391 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 ...
8
votes
2answers
344 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 ...
8
votes
1answer
449 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 ...
8
votes
2answers
2k 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 ...
8
votes
1answer
2k 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,...
8
votes
1answer
798 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 ...
8
votes
3answers
27k 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'...
8
votes
1answer
3k 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 ...
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 ...
8
votes
1answer
761 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,...
7
votes
4answers
985 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 ...
7
votes
2answers
3k 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 ...
7
votes
2answers
4k 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 ...
7
votes
3answers
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 ...
7
votes
1answer
784 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 ...
7
votes
1answer
8k 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. ...
7
votes
2answers
6k 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 ...
7
votes
2answers
37k 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 ...
7
votes
2answers
567 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 ...
7
votes
1answer
138 views

Quiz game with timer

This is my first Go program. I would like to know what could be improved, what is done wrong, and anything else that I should know. The CSV contains 10 questions with the 10 answers separated by a ...
7
votes
1answer
54 views

Refactoring a phantom server called Swayzee

I have made a tool that is pretty useful for me. I have made it open source on github. It is a server that listens for requests and returns an HTML static version of a single page app. It works with a ...

1
2 3 4 5
9