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
1
vote
0answers
32 views

infinite generator with eviction

I made a struct that will loop through a list, and return the next element on calls to the Get() method. It also allows to remove elements from the list by calling the Evict() method, and is safe for ...
1
vote
1answer
58 views

Banking application - Optimizing java multi-threading code

I created a simple Bank application to make multiple transactions between multiple accounts. It is working as expected. But I want to know can I make the code more optimized. ...
4
votes
1answer
49 views

One consumer and two producers using threads

I have based this code on Producer-Consumer Threading on Real Python. The idea is that I have 2 producers: One producer will give result every 0.4 to 0.7 seconds, depending on REST call. The second ...
1
vote
0answers
37 views

Dealing with Future#get and InterruptedException Sonar java:S2142 [closed]

In some legacy code I have inherited, there is a snippet that looks similar to this. ...
1
vote
0answers
28 views

Executing two database queries concurrently in Go [closed]

I would like to execute two database queries concurrently for quicker response time. Since channels seemed to be too verbose, I came up with the solution below. However, I'm not very confident about ...
3
votes
2answers
48 views

Simple multiple producer and single consumer concurrency pattern

Anyone please review and share your feedback for the following code. Multiple producers generate random integer numbers and a single consumer receives it to display only odd numbers out of it. ...
1
vote
1answer
83 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 ...
5
votes
3answers
897 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. ...
7
votes
2answers
280 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 ...
3
votes
0answers
339 views

Hosted service for queuing and running tasks in parallel in ASP.NET Core

I am attempting to construct a background service for an IIS-hosted ASP.NET Core project that basically queues tasks and runs them, and I decided to go with the ...
2
votes
2answers
51 views

Recursive Mergesort using goroutines

When learning a new language, one of my first tasks I like to go through is writing a few different sorting algorithms in that language to help familiarize myself with the syntax and see if there are ...
1
vote
0answers
96 views

Thread Safe Bank Transaction: Deposit, Withdrawal, Check Balance and Transfer in Java

I have made a class which is a thread-safe implementation supporting Deposit, Withdrawal, Check Balance Querying and Transferring of money. I have a class Account: ...
3
votes
1answer
80 views

Code to print even and Odd number using two threads

Below I am giving you my code which I wrote to print even number using even thread and odd number using odd thread sequentially. Could anyone please validate my code whether it is correct way of ...
2
votes
1answer
64 views

Concurrency-safe task scheduler

I'm trying to do some task scheduler and worker. Tasks are added to the queue from which worker retrieves and processes them. Tasks from one queue must be executed sequentially. Tasks from different ...
2
votes
1answer
288 views

Simple Producer-consumer implementation in Python

I implemented a simple solution to the Producer–consumer problem that I'd love for you to take a look at. The producer simply adds random numbers to a queue and the consumer (from a separate thread) ...
2
votes
0answers
65 views

Concurrent execution and coordination of C# tasks

I have a class, 'TaskCoordinator' which has 'BaseTask's applied to it. The BaseTasks have OnStarted, OnFinished and OnCancelled events which are triggered to notify the calling class of their events....
3
votes
0answers
42 views

Concurrency control between a non-blocking and a blocking methods

In this program, there is a list of Holders that is managed by a singleton class. Each of the Holders keeps a copy of the ...
4
votes
1answer
1k views

Asynchronous parallel ForEach implemented using Task.Run

I wrote a simple implementation of aysnc parallel.ForEach( ... ) All it really does is create a list of tasks and wait for them all to complete and aggregate the ...
3
votes
1answer
41 views

Count Words in Quotes Fetched from Website

I have solved the following exercise and would like to get some feedback on my implementation. Create a function that uses futures to parallelize the task of downloading random quotes from https://...
10
votes
4answers
2k 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 ...
4
votes
2answers
737 views

Unisex Bathroom problem without semaphore

Could I ask you to evaluate my solution to Unisex Bathroom Problem? Problem description An office has a bathroom that can be used by both men and women, but not both at the same time. If a man is ...
3
votes
1answer
126 views

Find shortest path in the matrix for multiple objects

I have the implementation of A* search algorithm that allows to find the shortest path from start to goal. The implementation looks like this ...
5
votes
2answers
164 views

Async concurrency prevention class

Because I'm quite naive regarding C#'s Task Asynchronous Programming and concurrency in general, and because it's so difficult to test, I'm concerned about the safety of this code. It's likely that ...
7
votes
1answer
70 views

Concurrent Queue Adapter

There's lots of code out there for basic adapters of std::deque to provide a thread-safe queue. I've adopted that, but wanted to provide a relatively full analog to ...
11
votes
2answers
534 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: <...
3
votes
1answer
125 views

Determine concurrent access to a function

Someone asked here how to determine a function is being called from multiple threads. My take on this is that they are asking about concurrent access not sequential access. The accepted answer ...
2
votes
1answer
120 views

Performing an action which may return other actions to be performed, concurrently

I have a program which, at its core, involves repeatedly performing an action on some value, and based on that action also returning a list of new values to perform that action on. The pure version of ...
1
vote
0answers
24 views

Process 2 lists concurrently with the first list adding to the second [closed]

I'm new to multi-threading and concurrency. I've got 2 lists that I want to process concurrently. Processing both lists requires a lot of time.sleep() and waiting for other servers to finish, so I ...
1
vote
2answers
205 views

Multi-Threaded Cellular Automata Lab

I am trying to improve the performance of my cellular automata lab. I have two arrays of Doubles representing the current values and the next values. If I run the ...
1
vote
0answers
20 views

Take a list of ascii strings from a file and hash them using python threading

How can I do this in a more performant way? I'm concerned that throwing the data in a queue like this is defeating the purpose of yield from the ...
2
votes
0answers
41 views

Comparing Java Semaphore versus ReentrantReadWriteLock

In this post, I attempted to compare the performance of two concurrency constructs: java.util.concurrent.Semaphore, ...
2
votes
0answers
390 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 ...
5
votes
1answer
2k views

Safely executing background tasks in parallel in ASP.NET Core

Context and initial idea I'm trying to teach myself the CQRS and Event Sourcing patterns by developing a simple ASP.NET Core application, loosely following Greg Young's example CQRS implementation on ...
7
votes
1answer
130 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 ...
3
votes
2answers
80 views

Download and save bulk URL concurrently

I am new to Go and wrote program to download and save bulk URLs concurrently. It is working correctly, but I would like to make it more efficient and follow best practices. ...
3
votes
2answers
1k views

java Thread-safe LRUCache implementation

What is best way to implement thread-safe LRUCache in java? Please review this one. Is there any better approach which can be taken here? ...
0
votes
1answer
98 views

Finding the longest Collatz sequence using Go, concurrently

I am working through this problem on project euler. Basic purpose of the code: ...
4
votes
1answer
173 views

Reader Writer SpinLock

I'm quite new to C++ and want to focus on writing performant multithreaded code because I will try to port our company internal GUI framework which is currently implemented in C#. So I'd love to get ...
4
votes
2answers
71 views

Upload a directory, in parallel, to an artifact repository

This code uploads an entire directory and allows for its reparenting on a remote server (an artifact repository). Three concerns: Copying the files locally takes a lot of space. Ideally, I could use ...
2
votes
2answers
2k views

Golang execute several go routine in loop and then wait

I'm new in Go and excited with its easy-to-use concurrency implementation. However I'm not sure if I'm doing it right in Golang way. Consider the code where I spawn ...
2
votes
1answer
53 views

Batch downloading to file or memory

This is likely my first useful piece of Rust code. Planning to crate-ify it. It works. ...
5
votes
2answers
115 views

Using two threads to increase RFC1951 Deflate compression performance

I have modified my implementation of RFC 1951 "Deflate" compression to use two threads. One thread performs the LZ77 matching, looking for sequences of at least three bytes that occur earlier in the ...
5
votes
2answers
114 views

Automatic RAII wrapper for concurrent access

Probably many people had to work with multithreaded applications with C++ and can understand how messy can be fine-grained locking of objects. So once in a while I came to idea of implementing some ...
1
vote
0answers
71 views

Critical section around given key

I would like to know if there is any pre-existing implementation of my solution so I don't have to reinvent the wheel. What I'm trying to create is an utility which allows me to create critical ...
4
votes
1answer
114 views

Reading shards from a Kinesis stream

Here is part of my implementation of reading a Kinesis stream. I am not confident that this is the best way to implement synchronizing returns from goroutine. Assuming there are N shards in the ...
3
votes
2answers
637 views

Go grep command clone

I am trying to make a simple clone of the command line utility grep. I'm working on it just for fun and to practice Go. The thing is, I am trying to make it in a way that if several files are given at ...
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 ...
2
votes
0answers
674 views

Golang gRPC context to check if cancelled or if deadline is exceeded while running function code

I am writing a gRPC Golang application and am looking for the best way to check if the deadline is exceeded or if the client cancelled the call. On the server side I created a channel called ...
3
votes
0answers
267 views

Linked list with hand-over-hand locking

Follow-up to this question: after reading the comments, I decided to redesign my linked list to have a cursor that only contains one node and implement the interface similar to the one of forward_list ...
6
votes
1answer
398 views

Specialized ConcurrentLinkedList

I need a concurrent data structure with the following properties: Low overhead for enumeration Insert only at end. Removal from any point. Enumeration should be safe with concurrent writing ...

1
2 3 4 5
8