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.
463 questions
0
votes
0
answers
52
views
ReadWrite Lock compatible with coroutines
A while ago I wrote for my own needs a (non-reentrant) read-write lock for kotlin's coroutines. I got no reactions on the relevant github thread. I think it's a nice code, so I thought I'd share it ...
4
votes
3
answers
707
views
Multithreaded array summation in Java - best practice, structure, acceptable use of Constant classes. There is no concurrency?
The task is educational. The basic functionality is working. Here are some questions for my code. Please give me feedback.
Main:
Architecture & Design: Is the decomposition appropriate? Should ...
1
vote
1
answer
65
views
Generate Serial number based on column value in sql server
I have table called cash_voucher it has some columns.
I want to generate voucher number based location id.
I mean generates voucher numbers starting from 1 for each location
For example location id is ...
1
vote
0
answers
65
views
Lock free Leaky Bucket Rate Limiter
I want to validate my solution for a lock-free leaky bucket rate limiter. Given a queuing capacity and rate limit per second, it should queue requests till capacity is reached and it should allow only ...
1
vote
2
answers
167
views
ProducerConsumerSimulation.java: practicing concurrent programming in Java
Intro
This time, I was in the mood for concurrent programing (ProducerConsumerSimulation.java). To this end, I have ended up with the code below. My primary concerns are:
Class design is trash,
The ...
5
votes
1
answer
104
views
Find food related words in German: Seeking Feedback on Concurrency and Code Organization
I'm developing a pipeline that processes unknown ingredient data from the OpenFoodFacts API. The goal is to find valid German words that are not yet in their taxonomy.
The tool performs the following ...
2
votes
1
answer
100
views
Multithreaded Merge Sort Using ForkJoin Framework
I've implemented a multithreaded merge sort using Java's ForkJoin framework, and I wanted to gather feedback on its correctness, efficiency, and scalability.
Here's my implementation:
...
4
votes
1
answer
113
views
Go Program for Concurrent FHIR Resource Uploads – Does it Achieve True Concurrent Requests?
I’ve developed a Go program to benchmark a FHIR server by uploading a dataset of FHIR resources concurrently.
The goal is to stress-test the server by sending a specified number (...
8
votes
2
answers
335
views
Multi-producer, multi-consumer blocking queue
Introduction
This is a queue that allows many producers to simultaneously write their items and many consumers to simultaneously read theirs. It's useful when construction and/or consumption could be ...
5
votes
2
answers
693
views
Thread-safe write-efficient register() method for a Load balancer
The code below was written for an interview question of designing a load balancer with only a register() method.
...
3
votes
1
answer
169
views
Amount Transfer Between Different Accounts - Improved Version
This is an improved code version for Amount Transfer Between Different Accounts
Welcoming any further improvements for this.
...
4
votes
1
answer
265
views
Amount Transfer Between Different Accounts
I implemented the below classes for transfer amount between different accounts. Used ConcurrentHashMap and Stamped Lock to handle concurrency.
Am I missing any important concepts here? Are there any ...
5
votes
2
answers
958
views
Reduce String Length With Thread Safety & Concurrency
I implemented the below URL Shortener class. Used ConcurrentHashMap to handle concurrency.
Short URL building logic may not be optimal, but it ensures that only ...
4
votes
2
answers
516
views
Implement service registry servers with load balancing strategies
Have Implemented below service registry class with 2 load balancing strategies.Used Strategy Pattern. Used Stamped lock ( Optimistic write locking) for ensuring thread safety and concurrency. Used ...
3
votes
2
answers
230
views
Data pipeline that handles errors and cancellations
I have code that concurrently reads data from a stream, processes elements, and writes the data to another stream. Each of these individual operations may fail, in which case I want processing to halt ...
4
votes
1
answer
422
views
Did I write the locks properly to prevent concurrency issues?
There may be a dozen things that could be improved about this code, but it's just a very quick proof of concept and for the sake of this post I'm specifically wanting to know if someone can verify ...
1
vote
1
answer
69
views
Distributed locking with fencing token implementation in Golang
I was reading about the implementation of distributed locks where we need to verify the lease using a fencing token as per this article - https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-...
3
votes
1
answer
93
views
A Simple BlockingQueue implementation in C++
I'm just dusting off my C++ knowledge in area of multithreading.
I started with implementing a producer-consumer pattern inspired by https://jenkov.com/tutorials/java-util-concurrent/blockingqueue....
2
votes
2
answers
169
views
A thread-safe performant Money Transfer API in Java
This is a popular interview question. It is meant to be done within 30 minutes. The task is to implement a thread-safe performant Bank Account API that allows to transfer, deposit, withdraw and check ...
5
votes
2
answers
982
views
Simple load balancer
I would like to know the possible improvements in design and concurrency of the following load balancer:
ability to add/register new instance
keep max of 10 instances for load balancer
forbid ...
7
votes
2
answers
1k
views
A thread-safe performant URL Shortener in Java
This is a popular interview question. It is meant to be done within 45 minutes. The task is to implement a thread-safe performant in-memory URL Shortener.
My implementation is based on two maps that ...
2
votes
1
answer
85
views
Can I use only mutex and condition variable Instead of the Banker's Algorithm?
I've been studying the Banker's Algorithm and was curious if I could implement a similar resource management system using only Mutex and Condvar. The code I wrote is a synchronization program that ...
5
votes
3
answers
150
views
Time based cache for single element
The container should be thread safe and provide lazy load of data, and cache the data for set period of time.
...
2
votes
2
answers
169
views
Multiple Producer and Multiple Consumer Implementation Using Locks and Semaphore
This solution has a total of four classes.
Main.java: Class with main method. Execution starts here.
...
2
votes
3
answers
157
views
Simple rwlock implementation in C
Can someone please review my rwlock implementation to see if there are any issues with correctness (hopefully not), give any feedback on how to write good C code etc, design patterns which could be ...
2
votes
1
answer
115
views
Multi Threaded File Processing C++
Background:
The program reads 1000000 lines in the file. Every four line will be parsed into an object in a vector. If it has 2 objects with the same name, it will drop 1 object and increment one of ...
4
votes
1
answer
78
views
Blocking lock for dpkg
My deployment and configuration process entails multiple processes trying to invoke dpkg on my VM at the same time. While dpkg has a locking mechanism, it causes anyone not holding the lock who is ...
1
vote
1
answer
137
views
decorator for an Executor that allows to get a List of running tasks
As stated in the javadoc below, this is intended for monitoring and debugging. I've found it especially useful for figuring out which tasks got stuck and prevented clean terminations of my ...
2
votes
2
answers
260
views
Circular Queue Producer Consumer with Mutex and Condition Variable vs. Sempahore
How can I optimize the performance of the code below? Destruction of the condition variable at the end of main blocks, not sure why this behavior is occurring. Is it possible to remove some of the ...
2
votes
1
answer
896
views
Efficient parallelization of small tasks
Problem statement: Consider a scenario where a vector of very small tasks, each encapsulated within a class 'Task' with a thread-safe method Task::process(), needs to be efficiently processed in ...
1
vote
0
answers
116
views
Tkinter threadpool with callback implementation - alternative approach feedback
This is an attempt to create a usable alternative to the "normal" method of implementing concurrency with tkinter. The "normal" method seems to be by pro-actively polling a result ...
5
votes
4
answers
2k
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 ...
2
votes
1
answer
297
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 ...
4
votes
1
answer
168
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" ...
2
votes
1
answer
886
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
67
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
...
6
votes
1
answer
955
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
357
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 ...
1
vote
1
answer
263
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):
...
2
votes
1
answer
248
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 ...
2
votes
1
answer
1k
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 ...
0
votes
1
answer
90
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
...
1
vote
1
answer
199
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
232
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 ...
2
votes
1
answer
229
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
162
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
899
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
...
3
votes
1
answer
173
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 ...
4
votes
1
answer
613
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 ...
2
votes
1
answer
526
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 ...