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
4 votes
4 answers
1k views

Yet another shared_ptr implementation for learning purposes

C++ shared_ptr implemented as a coding practice and learning purposes. It uses std::shared_ptr interface. Basic tests are included (using single header Catch 2) Some methods are omitted to keep the ...
-1 votes
0 answers
25 views

Counting unfair semaphore implementation in Java [closed]

I am implementing Java's Counting Semaphore's acquire() and release() methods and using it in a multi-producer-consumer problem. Semaphore class ...
2 votes
1 answer
88 views

High-write low-read thread-safe counter

I need a thread-safe counter that will see frequent increments but will be rarely read. This counter will be used to emit metrics, for example, the hit rate of a ...
3 votes
1 answer
248 views

Correct synchronization of reads and writes to ConcurrentHashMap and ConcurrentLinkedQueue

I am writing a web application (Servlets, JDBC, no Spring - for learning purposes) that accepts orders from customers, while registered couriers can choose which one of these orders they want to ...
3 votes
1 answer
140 views

synchronized access to HttpSession attribute vs static ConcurrentMap with HttpSessionListener

As a part of library implementing websocket Guice scopes I need to maintain an object related to each HttpSession called ...
0 votes
1 answer
117 views

Lock-free implementation of getAndUpdate() using atomic CAS (Compare-And-Swap) operation

We have the following class written in Kotlin Native with the new Memory Manager (which doesn't require to freeze objects): ...
0 votes
0 answers
29 views

Synchronisation access to a shared class in Python server with async/await

Last week I wrote a simple server on FastApi to run ML model to classify a text on Chinese (split text on separate words). When I had clarified work of this model with API, it became time to confirm ...
4 votes
1 answer
96 views

Packet generation and consumption

I have the following simplification of a program which consists of 2 threads. One thread pushes packets to the back of a deque while another waits for user input before performing a "heavy" ...
3 votes
1 answer
122 views

A mutex that can detect certain types of programming error

This mutex prevents concurrent access to a target resource. One key requirement is the ability to be acquired in a (scheduler) thread and released in a different (worker) thread. Unfortunately this ...
2 votes
1 answer
182 views

Parallel handling db queries is very slow in C#

I have SignalR app that publishes sent messages to Redis. My console app subscribe to channel where these messages are sent, deserializes it and saves in database. Problem is with handling these ...
1 vote
1 answer
195 views

Concurrently write results to SQLite database

The goal is to run a function compute in parallel on many inputs (10**6 in total, say) and store the results. Each call to ...
3 votes
1 answer
246 views

Golang function that reads S3 files and populates maps with strings as keys

I have a below read function which is called by multiple go routines to read s3 files and it populates two concurrent map as ...
1 vote
1 answer
43 views

Client <> Query <> Subquery Bookkeeping

Context I am making a system, where different clients issue queries A query is resolved by issuing a set of subqueries I have an invalidation-worker, which gets notified when subqueries go stale ...
5 votes
1 answer
700 views

Golang Tour Web Crawler Exercise

In the last few days I've played around with Go a little and took the language tour. The last exercise (text here) requires you to crawl a graph that simulates a set of Web pages with links, using ...
2 votes
1 answer
291 views

Sender/Receiver threads using std::unique_lock and std::condition_variable

The code below is a sender/receiver setup in C++ where the sender is in one thread, the receiver is in another, and the data being sent/received is "shared" (global). The code uses the ...
6 votes
1 answer
473 views

Simple, fool-proof pattern to execute tasks in parallel

Assume I have a type task_info that stores the task-specific data needed to execute the task. A std::vector of those is built ...
3 votes
2 answers
226 views

atomic spinlock mutex class

This here is the follow-up to this question. I was recommended to implement a Lockable type (similar to std::mutex) that can work with ...
5 votes
3 answers
998 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 ...
3 votes
0 answers
120 views

Order guaranteed recursive_transform template function implementation with execution policy in C++

This is a follow-up question for A recursive_transform Template Function with Execution Policy, A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy ...
2 votes
1 answer
143 views

C++20 simple RwSeqLock

I recently discovered the atomic wait/notify mechanism in C++20 and wrote this readers-writer lock in the style of Linux kernel Seqlock. Writes have to be inside a lock/unlock, while reads are ...
6 votes
5 answers
582 views

Convert FLAC files to MP3 in parallel on Ubuntu

I created a script to convert my FLAC music collection to MP3. I did this so that I can play the MP3 files in my car, as the integrated head unit only supports MP3 and WMA files. The script works on ...
0 votes
1 answer
140 views

A producer (mapper) and consumer (reducer) problem with concurrency in go with race conditions

Link to go playground https://go.dev/play/p/ctQDpDW6pui This code has been based on suggestions and conversations in this thread here Architecture: A read method creates a channel shared with ...
0 votes
3 answers
193 views

Delayed, concurrent event stack in Java

(See the next iteration: Delayed, concurrent event stack in Java - follow-up ) Motivation I was confronted with a task of having "message events" for a GUI program. The use case is as ...
0 votes
1 answer
59 views

Delayed, concurrent event stack in Java - follow-up

I have slightly refactored the Delayed, concurrent event stack in Java. Now it looks like this: DelayedEventStack.java ...
2 votes
1 answer
154 views

Distributed lock service implementation in Golang

I have multiple E2E tests (written in Java) which share login details, each test during runtime will query the locker API for login details which is running on its own dedicated server. Below is my ...
2 votes
1 answer
112 views

Thread Pool Class

I have a thread_pool class, that mimics std::thread. (I would have liked std to have a pool, but alas that is not the case.) thread_pool.h ...
4 votes
1 answer
440 views

Thread Safe Queue

I have a thread safe queue in my library c9y. It is generally used as a task queue in the task_pool class, but in can be used for any producer / consumer problem. queue.h ...
4 votes
1 answer
3k 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 ...
1 vote
0 answers
169 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 ...
4 votes
1 answer
324 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 ...
1 vote
1 answer
120 views

Concurrent dependant routines in a gui application [closed]

The idea is that, in my application I have 5 routines named long_process_1, long_process_2, ...
1 vote
1 answer
38 views

Bulk recompiling edits to files by running external processes with a pool of 4 workers using asyncio

I am bulk recompiling edits to a c-like language which uses an external compiler.exe. The compiler takes the file paths as arguments and does the processing, nothing needs to be synchronized simply ...
4 votes
1 answer
111 views

Approximate concurrent counter in Rust

I am reading chapter 29 of OS: the three easy pieces, which is about concurrent data structures. The first example these is an approximate counter. This data structure increments numbers by using a ...
3 votes
1 answer
223 views

Obtaining intermediate results from a continuously running background thread in Java/JavaFX

This is a question about Java/JavaFX concurrency. Specifically, how can the UI request intermediate data from a thread running in an infinite loop. I have a simulation program in Java and JavaFX. The ...
4 votes
3 answers
6k views

Matrix multiplication with OpenMP parallel for loop

I tried implementing matrix multiplication with parallel for loop in OpenMP as follows. It runs correctly but I want to make sure if I'm missing anything. How does this determine the number of threads ...
2 votes
2 answers
93 views

Threadsafe LRU Cache

Trying to design a threadsafe lru cache using a reentrant lock. Currently I don't like the tryLock in a loop approach. Any inputs on making it more optimal in terms of concurrency? ...
2 votes
2 answers
61 views

Load data from database, change it asynchronously and return the new data

I have written this function to load data from the database, change it asynchronously and return the new data. It appears to work fine, but since I am new to Kotlin, I wanted to ask if this code is ok ...
4 votes
1 answer
283 views

Launching two goroutines in parallel and returning result of the first finished

Real case: I need to retrieve data from a web service (main process), but in case that web service is taking too long, I retrieve the data from the cache (that data might be older) in a parallel ...
4 votes
1 answer
109 views

Task executor thread pool

Despite my experience with Java, I am not well-versed with concurrency. I wrote this thread pool that has a queue of tasks. Please ignore any signature choices, such as overuse of ...
2 votes
2 answers
488 views

Golang implementation of dining philosophers variant

I would like to implement a variant of the classical dining philosophers problem which has the definition as: Implement the dining philosopher’s problem with the following constraints/modifications. ...
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 ...
1 vote
0 answers
72 views

Set up pub/sub service as part of web app in Go

I have a web application that I'm writing in Go, using the Iris package. This app needs to listen to Azure Service Bus for messages, and take action when they come in. This is my first time writing ...
1 vote
0 answers
163 views

Converting future.get() to CompletionStage.whenComplete()?

I currently have some code in Java which looks something like this, but I want to refactor this. ...
7 votes
1 answer
1k views

Tool to calculate the average time that takes for a GitHub pull request to get merged

I'm learning Go, and this is my first attempt at a command-line tool that uses the GitHub API to calculate the average time that takes for a pull request to get merged for a particular organisation or ...
4 votes
1 answer
155 views

SHA256 password cracker - v2 with concurrency

I have updated my previous code with the suggestions. I have also implemented concurrency to speed up the results. I'd be interested for comments on a more efficient use on concurrency / parallel ...
2 votes
1 answer
1k 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 ...
1 vote
0 answers
216 views

What’s the correct usage of volatile keyword in this Concurrent dictionary implementation?

Can I get some guidance around the usage of volatile keyword and design of the existing concurrent dictionary implementation, please. Here are a few design ...
3 votes
1 answer
214 views

Lock-free, thread-safe trie container

This is a Trie data structure for mapping strings to integers or pointers in O(n) time. Based on the idea that we never delete anything from the container, we can perform concurrent read/write ...
2 votes
1 answer
266 views

Read bunch of files in parallel and populate concurrent map

I am trying to read bunch of S3 parquet files in parallel from a S3 bucket. After reading all these files, I am populating my products and ...
5 votes
2 answers
958 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 ...

1
2 3 4 5
10