Skip to main content

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.

Filter by
Sorted by
Tagged with
1 vote
0 answers
25 views

Java multithreading with Spring JPA

I have to improve a process that is currently sequential, and i wanna make it multi-thread. This process uses Spring JPA, with spring boot 2 and java 17. I would like to have a feedback on the ...
Fabio Piunti's user avatar
0 votes
1 answer
73 views

Take photographs using simulated cameras that share a lock

I'm new to threading in Python. I want to use it to speed up taking images on my lab computer. I have the following dummy code: ...
AccidentalTaylorExpansion's user avatar
0 votes
0 answers
31 views

Messaging correlation and syncing

We use masstransit and sagas. But I also wanted to correlate some messages without the need for a saga since the syntax for those are pretty verbose if all your need is to sync on a correlation id. ...
Anders's user avatar
  • 660
3 votes
1 answer
241 views

Logging in a different thread using circular buffer C++

What it does The code creates a logger class which instantiates a circular buffer at construction and uses producer-consumer style approach using condition_variable to log and print the messages to ...
wwite's user avatar
  • 33
4 votes
1 answer
519 views

Lazily decode a buffer with a thread-safe Iterator

I have implemented an Iterator for my Pojo class. The purpose here is to lazily decode multiple ...
William's user avatar
  • 141
1 vote
0 answers
62 views

Lockless synchronized access to ConditionalWeakTable

I am inexperienced with writing multithreaded applications, and I am trying to wrap a ConditionalWeakTable (CWT) for use as a generalized container type. I'm aware ...
monkey0506's user avatar
2 votes
2 answers
139 views

Wrapping SemaphoreSlim.WaitAsync with an IDisposable

The usual way of dealing with a SemaphoreSlim is ...
Ackdari's user avatar
  • 141
1 vote
1 answer
111 views

SynchronizedObservableCollection: a thread-safe ObservableCollection

After reading many people talk about the need for a SynchronizedObservableCollection and their implementations I decided to roll my own. I wanted to add a ...
HackSlash's user avatar
  • 382
2 votes
2 answers
462 views

Thread safe accessing memory cache using semaphore

I have a Web API and for some requests we are sending requests to a third party API that requires request authentication. It's a simple bearer token, which I'd like to reuse across requests, because ...
Prolog's user avatar
  • 263
2 votes
0 answers
23 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 ...
cpicanco's user avatar
  • 499
3 votes
1 answer
476 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 ...
DeltA's user avatar
  • 133
2 votes
1 answer
111 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): ...
Oersted's user avatar
  • 337
7 votes
1 answer
1k 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 ...
Oersted's user avatar
  • 337
4 votes
2 answers
2k 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. ...
Darth-CodeX's user avatar
1 vote
1 answer
164 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 ...
Christian Findlay's user avatar
4 votes
1 answer
968 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. ...
rickmanalexander's user avatar
6 votes
1 answer
466 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 ...
EternalLlama's user avatar
1 vote
0 answers
142 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 ...
C-F's user avatar
  • 111
8 votes
3 answers
2k views

Basic RAII spinlock class

I have written the following class that acts as a simple lock for mutual exclusion: ...
digito_evo's user avatar
2 votes
0 answers
167 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 ...
John Goode's user avatar
6 votes
2 answers
2k 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 ...
andylvua's user avatar
  • 215
7 votes
2 answers
918 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. ...
Edziju's user avatar
  • 319
7 votes
1 answer
487 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, ...
Macmade's user avatar
  • 171
4 votes
2 answers
300 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 ...
Lee's user avatar
  • 43
2 votes
1 answer
132 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 ...
rioki's user avatar
  • 462
2 votes
1 answer
77 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 ...
optimistic's user avatar
1 vote
1 answer
284 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....
Daniel B's user avatar
  • 146
3 votes
2 answers
232 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 ...
Dexter's user avatar
  • 415
0 votes
1 answer
559 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 ...
Russ's user avatar
  • 133
3 votes
1 answer
3k 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 ...
Anonymous's user avatar
  • 131
2 votes
1 answer
2k 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 ...
Developer Paul's user avatar
9 votes
2 answers
1k 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 ...
LambBrainz's user avatar
3 votes
2 answers
2k 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: <...
user2793618's user avatar
1 vote
1 answer
97 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 ...
vinter_man's user avatar
5 votes
2 answers
2k 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 ...
Developer Paul's user avatar
1 vote
1 answer
202 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 ...
emrepun's user avatar
  • 165
4 votes
1 answer
220 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 ...
trinalbadger587's user avatar
3 votes
1 answer
2k 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 ...
wcochran's user avatar
  • 141
7 votes
3 answers
1k 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 ...
Primrose's user avatar
4 votes
1 answer
4k 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, ...
elmer007's user avatar
  • 143
0 votes
1 answer
63 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 ...
DocDriven's user avatar
  • 161
5 votes
1 answer
1k 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 ...
DocDriven's user avatar
  • 161
5 votes
2 answers
4k 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 ...
Developer Paul's user avatar
2 votes
1 answer
222 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 ...
temp's user avatar
  • 121
-2 votes
1 answer
96 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. ...
Barcelona's user avatar
  • 105
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: ...
Mate de Vita's user avatar
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 ...
Matt W's user avatar
  • 157
2 votes
2 answers
643 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. ...
MHebes's user avatar
  • 143
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? ...
Zebra's user avatar
  • 31
1 vote
1 answer
97 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 ...
sync101's user avatar
  • 13

1
2 3 4 5
10