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
11 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 ...
user avatar
8 votes
2 answers
577 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 ...
user avatar
3 votes
2 answers
109 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: <...
user avatar
1 vote
1 answer
37 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 ...
user avatar
4 votes
2 answers
126 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 ...
user avatar
1 vote
1 answer
64 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 ...
user avatar
  • 165
4 votes
1 answer
97 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 ...
user avatar
3 votes
1 answer
126 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 ...
user avatar
  • 131
7 votes
3 answers
308 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 ...
user avatar
4 votes
1 answer
398 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, ...
user avatar
  • 143
0 votes
1 answer
41 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 ...
user avatar
  • 161
5 votes
1 answer
147 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 ...
user avatar
  • 161
5 votes
2 answers
841 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 ...
user avatar
1 vote
1 answer
131 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 ...
user avatar
  • 111
-2 votes
1 answer
84 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. ...
user avatar
  • 105
1 vote
0 answers
37 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: ...
user avatar
2 votes
2 answers
487 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 ...
user avatar
  • 157
2 votes
2 answers
103 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. ...
user avatar
  • 153
3 votes
4 answers
958 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? ...
user avatar
  • 31
1 vote
1 answer
78 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 ...
user avatar
  • 13
3 votes
0 answers
98 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 ...
user avatar
  • 31
5 votes
0 answers
111 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 ...
user avatar
1 vote
1 answer
177 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 ...
user avatar
3 votes
2 answers
112 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 ...
user avatar
3 votes
2 answers
2k 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 ...
user avatar
  • 195
4 votes
2 answers
204 views

Type agnostic, statically allocated, thread-safe queue in C

I need a queue in C for an embedded application in which I cannot allocate memory dynamically. I avoided using void* for the queue elements (which is not convenient ...
user avatar
  • 299
1 vote
0 answers
79 views

Thread Safe Python Client Server Service

I had like to get some feedback about my Thread Safe Python Client-Server example. Is it really thead-safe? Do you see any dead-locks or other thread-safe problems? https://github.com/icarpis/...
user avatar
  • 11
1 vote
2 answers
838 views

Returning data reference with mutex lock guard struct

I'm writing a multi-threaded program where some external part of the program needs access to a large piece of data that's controlled by my class. I'm trying to return a reference to this data in a ...
user avatar
  • 151
1 vote
0 answers
34 views

Stoppable asyncio thread class

A threading.Thread subclass intended for running an asyncio loop that has the ability to be stopped gracefully from another ...
user avatar
  • 625
2 votes
1 answer
502 views

Parallelized web crawler using goroutines and channels

As part of the "a tour of Go" section on golang.org, I was trying to make a (formerly singlethreaded) web crawler parallelized using goroutines. I got it working but it doesn't seem to "...
user avatar
  • 8,392
0 votes
1 answer
103 views

Class to share data between two threads implemented as FIFO with std::queue

I am trying to improve my code that involves a thread (threadA) handling some UDP communication and another thread (threadB) ...
user avatar
  • 19
5 votes
0 answers
117 views

Thread safe optimized list

Last week I was challenged in a technical interview with a code challenge about threads and efficiency. The challenged required to create a service to detect whether an ID had been already seen or not....
user avatar
3 votes
1 answer
528 views

A 'ThreadSafe' Observable Collection - C#

Seeing as a concurrent collection does not exist in .net that allows specific items to be removed, I have put together the following class. It's important to note that it is only threadsafe until the <...
user avatar
  • 131
2 votes
0 answers
215 views

Is this a good pattern design for a Unity dispatcher for creating thread safe methods?

Well, my intention here is to allow users to execute Unity methods/properties in other threads by using this Dispatcher implementation: ...
user avatar
  • 227
2 votes
0 answers
77 views

Sequential writing and reading (two threads)

I am new to Java. My task is to create a SequentalWriter class and a SequentalReader class that implement the Runnable interface....
user avatar
4 votes
1 answer
1k views

Is my implementation of a C++ setTimeout thread correct?

I've implemented a setTimeout thread similar to the one in JavaScript (new to thread programming) In the example on this page I see use of an atomic variable ...
user avatar
4 votes
0 answers
89 views

Game of Life, thread per cell

In an effort to learn Java's support for concurrency I solved a self-imposed exercise to write a Game of Life simulator in Java, running a separate thread for each cell. Here is my code: ...
user avatar
  • 571
2 votes
1 answer
91 views

Multiple producer single consumer on the same thread

I implemented a multi-producer single consumer class, with an important restriction that once the consumer started working, it must continue its work on the same thread (the reasoning behind this is ...
user avatar
  • 1,157
6 votes
1 answer
83 views

Extract text file from zip, parse content and post to azure queue storage

Problem I'm trying to create the most performant code to: Extract a text file from a zip parse its content serialize class post to Azure Queue Storage Scenario 4 times per year I receive 20 zip ...
user avatar
5 votes
1 answer
99 views

Double LinkedList Deep Copy in Kotlin with Generics and Thread Safety

Goal Return a deep copy of a double LinkedList. Each node also contains an additional random pointer, potentially to any node or null. Code to start ...
user avatar
7 votes
0 answers
146 views

Implementing GSL synchronized_value

Core Guidelines mention a type synchronized_value<T>, which supposedly pairs std::mutex with the internal value. I couldn'...
user avatar
8 votes
2 answers
821 views

C# threading and synchronizing methods

So I started this question, I believe i have synchronized the methods correctly, need some insight on whats wrong and what should be done. I have to modify ths class Purse so that the method AddCoin ...
user avatar
  • 81
5 votes
1 answer
43 views

Prototype of background save facility

I have developed NoSQL database. At the moment it has no threads (async). When the database needs to save data to disk, it blocks connections until it saves. This method works OK, because save is fast ...
user avatar
  • 1,234
5 votes
1 answer
937 views

Count of request per second, minute in java

I want to count number of requests per second, minute. I want do it fast and thread-safe. I have 2 variables to count: ...
user avatar
  • 151
4 votes
1 answer
2k views

Barrier implementation in C++

I've implemented a barreir in C++ close to one showed here. In the project code it's used only with two threads and seems to work. A synthetic test didn't expose any flaws too. But I suspect that on ...
user avatar
  • 149
3 votes
1 answer
77 views

Update cache with minimal blocking

As part of the task, it is allowed to use slightly outdated data. It is required that only one thread per key is involved in the critical section, while the remaining threads use data from the cache ...
user avatar
  • 131
4 votes
1 answer
116 views

Job_Queue (Thread_Pool) Program

I'm new to std::atomic, std::mutex, std::unique_lock, ...
user avatar
3 votes
1 answer
251 views

A thread-safe typed Promise implementation in Java for Android

Introduction I've created a typed Promise implementation in Java for Android, borrowing ideas from this article for a JavaScript implementation, by Forbes Lindesay. To allow for "asynchronicity", my ...
user avatar
  • 178
3 votes
1 answer
176 views

C code using process synchronization and multi-threading

This is a matrix-vector multiplication program using multi-threading. It takes matrixfile.txt and vectorfile.txt names, buffer size, and number of splits as input and splits the matrixfile into ...
user avatar
  • 33
1 vote
1 answer
217 views

Is this locked use of a Java HashMap thread safe?

I am trying to improve the performance of one of my project's methods, which obtains the command line of a process using WMI. A summary of key points: The method is on an object representing a ...
user avatar

1
2 3 4 5
11