Questions tagged [thread-safety]
A piece of code is thread-safe if it only manipulates data structures in a way that allows consistent execution of this code by multiple threads.
485
questions
-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
0
answers
11
views
Recording/Playback thread device in Object Pascal
I have developed an audio recording and playback base device in Free Pascal. This device is built on Free Pascal's TThread class and utilizes the low-level audio ...
3
votes
1
answer
61
views
C++ Readers-Writer Lock using Asio's Strands
The locking mechanism is implemented in the class RW_Lock.
The saved_async_completion_handler structure is used in ...
0
votes
0
answers
100
views
For loop vs If statement using conditional variable
I'm extending the sync.Pool type by limiting the amount of objects that can reside outside the pool. To achieve this I'm using ...
2
votes
1
answer
98
views
C++: algorithm that uses fixed-size buffer of data that are produced in stream, faster than the algorithm speed; modified version
This is a, I hope, an improved version of this code, limiting atomic usage (following @GSliepen, @G.Sliepen advice) (NB I'm limited to, at most C++17):
...
7
votes
1
answer
960
views
C++: algorithm that uses fixed-size buffer of data that are produced in stream, faster than the algorithm speed
I try to implement this scenario with a producer/consumer multithread pattern and I'd like to optimize synchronization and memory model directive used.
This code originates from a SO question and its ...
0
votes
0
answers
36
views
Changing the state of an entity in a multi threaded environment using Stored Procedures
According to my current design various processes and threads(written in .net core or framework) will call this stored procedure to change the status of various entities in a multi threaded environment:...
4
votes
2
answers
1k
views
Multi-threading Class in C++
I wrote a C++ class which can take a vector of functions and their respective arguments and execute them in parallel and return a vector of results from its respective functions.
...
1
vote
1
answer
99
views
Dart Non-Reentrant Async Lock
This class synchronizes access to an async resource. If retainFutureErrors is false, it will keep retrying until there is a success. Otherwise, the ...
4
votes
1
answer
309
views
Threadsafe Non-Overlapping Timer
I was working on a project recently, where I needed to process some tasks periodically, but the execution of those tasks could not overlap with one another. ...
6
votes
1
answer
347
views
Synchonizing queue with mutex
I am trying to syncronize the queue between threads using mutex. I have 2 mil random integers in input.txt file. Main thread reads integers then puts them in queue. Other threads are simultaneously ...
0
votes
0
answers
90
views
Service Locactor with accessing service safely for .Net DI
I have implemented a service locator, but I am unsure if the services (instances) obtained from it can guarantee the security of the accessed or manipulated data.
In some classes where services cannot ...
1
vote
0
answers
77
views
Thread-safe key-value cache with expiration
I need my cache hold items to be accessible by key. The items should disappear after a configured time period. I do not need the lifetime of items to be exactly as configured. All I need is to make ...
8
votes
3
answers
1k
views
Basic RAII spinlock class
I have written the following class that acts as a simple lock for mutual exclusion:
...
2
votes
0
answers
108
views
Java Project Reactor/WebFlux token service
I'm trying to achieve a thread-safe reactive token service. The point is that all subscribers must wait until the token is received or updated (when expired). It works, but I want a second opinion ...
6
votes
2
answers
818
views
C++ Thread Pool Implementation using Lock Free Queue
Topic: C++ Implementation of Lock-Free Queue and ThreadPool classes
In a project I'm currently working on, I need the implementation of ThreadPool along with a thread-safe queue. I've tried ...
7
votes
2
answers
783
views
ThreadSafe std::queue
I have written a threadsafe queue and I would like you to suggest what can be improved and how to write good unit tests for this implementation.
...
7
votes
1
answer
216
views
C++ mutex-like class using std::condition_variable
On a project I'm working on, I have a need for a mutual-exclusion primitive behaving like std::mutex or std::recursive_mutex, ...
4
votes
2
answers
230
views
Multiplayer queue optimisation
I currently have code that is working but I think it can be optimised.
The code waits until a player joins and adds the player to a BlockingQueue if there is
not already a Player waiting then it ...
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
...
2
votes
1
answer
57
views
Force acquiring R/W lock
I am trying to build an abstraction that forces lock acquisition before data can be accessed.
This seems to work, but please tell me if what I am doing horribly wrong, and what I could improve.
I am ...
0
votes
0
answers
159
views
Design a thread-safe Hit Counter
I have designed a Hit Counter which can conveniently be used to design a Rate Limiter
Original question: https://leetcode.com/problems/design-hit-counter/
To make it thread safe, I used lock statement....
3
votes
2
answers
169
views
Thread-safe cached compiled Regex
I have a use case where I want to keep a pre-compiled regex, cached, for performance reasons, but the regex pattern also needs to be updated infrequently. Instances of CachedRegexFilter class will be ...
0
votes
1
answer
271
views
Deleting entities asynchronously in C#
I have a method that takes a collection of objects, and in turn calls a method that handles a single object. My question is, do I need to handle the tasks coming from the ...
1
vote
0
answers
2k
views
Implementation of Concurrent List in .NET
I would appreciate review of this implementation of the concurrent list that is, to my knowledge, currently missing in .NET Core.
Requirements
Thread safe
Lock free
Ordered
Supports get and set by ...
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 ...
8
votes
2
answers
915
views
Multithreaded bogosort in Rust
For some quick context, I'm fairly new to Rust and decided to give myself a difficult-but-attainable task of implementing a sorting algorithm. I chose bogosort (or stupid-sort, shuffle-sort, whatever ...
3
votes
2
answers
1k
views
C++ thread pool and thread safe queue
This is my first time writing a custom thread pool in C++. I would love some feedback on how my code looks and if I am missing best practices or have glaring/subtle issues. Thanks!
ThreadPool.hpp:
<...
1
vote
1
answer
67
views
Synchronization \ backup of directories and files (Python)
stackexchange members. I'm just learning to write. I set myself a task a few days ago and today I completed its implementation. The task was to create a "backupper" (I was inspired just by ...
5
votes
2
answers
955
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
vote
1
answer
159
views
Bank account concurrency problem Swift
I tried to implement a simple BankAccount class to practice providing a solution to the common Bank Account transaction data race problem. Reference to a description of such a problem can be found ...
4
votes
1
answer
190
views
Task manager object for lazy initialization
The Problem
I am developing a Visual Studio extension for importing code from a server.
Because of the way Visual Studio works, multiple threads could try to perform the same operation at the same ...
3
votes
1
answer
1k
views
C++ thread-safe object pool
This is a modern C++ implementation of a thread-safe memory pool -- I want to make sure I am solving the critical section problem correctly (no deadlocks, starvation, bounded waiting) and I am getting ...
7
votes
3
answers
992
views
Lock-free multi-producer / multi-consumer queue in C++
I've been working on a lockless multi-producer, multi-consumer queue in an effort to learn as much as I can about concurrency, without the use of mutual exclusion. The queue uses a bounded ring buffer ...
4
votes
1
answer
3k
views
C# Thread-safe singleton service for caching data used during lifetime of ASP.NET Core MVC application
Basic Background
I have an ASP.NET Core MVC application that uses Client (e.g., "customer") information for every HTTP request. The collection of Clients, as well as their information, ...
0
votes
1
answer
53
views
Type-agnostic abortion condition in Producer-Consumer model queue
This is a follow-up post to the topic discussed here.
Description
I am trying to implement a robust, multi-threaded producer-consumer model with a single producer in the main thread and several ...
5
votes
1
answer
846
views
Multithreaded Producer-Consumer model implementation
Description
I am trying to implement a robust, multi-threaded producer-consumer model with a single producer in the main thread and several consumers in other threads.
The generator thread loops over ...
5
votes
2
answers
3k
views
C++20 Thread Pool
I've implemented a thread pool using C++20. I'm fairly new to concurrently/multi-threaded programming and wanted to work on a project that I could learn from while also getting to know some of the new ...
2
votes
1
answer
200
views
Time-Sensitive Synchronized Transfer of Data Buffer in C# to Multiple Clients
This is a C# program that is a reference implementation, it will be used to make a C version after it is stable and bug free. The programs are supposed to simulate sensor data collection and ...
-2
votes
1
answer
94
views
Thread-safe collection to store Member objects [closed]
This is poorly written Java code, intended to implement a thread-safe collection to store Member objects and failing at doing so.
...
1
vote
0
answers
48
views
Thread-safe running mean and variance
In one of my personal python libraries I have a custom class used for computing the running average and variance of a stream of numbers:
...
2
votes
2
answers
3k
views
Simple MemoryCache implementation for thread safe caching
After much prompting from this post I wanted to build a simple, in-memory, thread-safe cache.
The only caveat (as far as I was originally concerned) was the need for two different absolute expiration ...
2
votes
2
answers
356
views
Creating a threadsafe, mutable, global configuration struct wrapper with C++17
I'm trying to create a relatively simple class that stores global configuration in some serializable struct, and reads/writes from/to a file.
My main goal is to make this class easy to use correctly. ...
3
votes
4
answers
2k
views
Multi-threaded merge sort
Below is the code for merge sort using multithreading. Will this code run for large number of inputs? Does any other part of the code need changing?
...
1
vote
1
answer
93
views
Simple Ratelimiter Feedback
I'm preparing for coding interviews and I wanted to get feedback on this question which asks you to write a simple ratelimiter that can handle 5 requests every 2 seconds for example. Since it is for a ...
3
votes
0
answers
210
views
C# class library for managing recurring background operations
I have written a class library for creating timer-based bacground operations in .NET projects. The idea is to be able to create and manage (start/stop/resume/cancel) recurring background operations ...
5
votes
0
answers
173
views
stable producer/consumer threads in python
I have implemented a producer/consumer functionality using threads in a given framework and
I'm pretty sure I did not cover all possible scenarios.
I made a small reproducible version. Lines ending ...
1
vote
1
answer
287
views
Java UDP port knocking authentication. Many clients at the same time
This is a student project of mine. I got 4/5 points but I suspect there's a lot of weird stuff in there. I never had a chance to hear my teacher's feedback about it and it bothers me so I figured ...
3
votes
2
answers
326
views
A toy example of the concurrent stack via atomic variables and CAS pattern
I've written a toy example of the concurrent stack which has only three functions push(), peek(), and ...
3
votes
2
answers
5k
views
ASP.NET Core singleton with a thread-safe property that can be changed
Thanks to ASP.NET Core dependency injection, there's no need to follow the Singleton pattern; any class will do.
What I want to do is to have a class that will store a value that'll be used by another ...