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.

53 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
0 answers
327 views

Implementing GSL synchronized_value

Core Guidelines mention a type synchronized_value<T>, which supposedly pairs std::mutex with the internal value. I couldn'...
Sergey Kolesnik's user avatar
5 votes
0 answers
177 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 ...
Raubsauger's user avatar
5 votes
0 answers
143 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....
Facundo La Rocca's user avatar
5 votes
0 answers
102 views

Testing application stability by throwing random diagnostic exceptions

I'd like to be able to better test application stability. Usually when you're doing this, you run the application and keep your fingers crossed that it won't crash when an error occurs (be it a ...
t3chb0t's user avatar
  • 44.1k
4 votes
0 answers
198 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: ...
gaazkam's user avatar
  • 561
4 votes
0 answers
117 views

Toggle any application feature ON or OFF - follow-up (v2)

This is the second version of my FeatureToggle service (see previous question). It still has the same purpose which is to help control whether a feature is ...
t3chb0t's user avatar
  • 44.1k
4 votes
0 answers
262 views

Type & Thread-safe Logger Implementation

So I had previously posted this question and asked for some feedback regarding my (now) header-only logging system and figured it would be a good time to go back to the changes I made it and see if it ...
Rietty's user avatar
  • 375
4 votes
0 answers
360 views

Wait free triple buffer primitive

I'm trying to write a triple buffer that's wait free for a update + render loop after being bitten by lock starvation one too many times (on a different project, using a library). For reference, a ...
AlterionX's user avatar
4 votes
0 answers
149 views

"Lock-free" one-shot event manager

Giving a review to Oachkatzl and recently about some other synchronization problems (Lazy with invalidate and some node-locking list), I wanted to test my skills and redesign it in most light-weight ...
user avatar
4 votes
0 answers
491 views

ConcurrentLinkedQueue Object Pool implementation

I have implemented this simple unbounded ObjectPool based on a ConcurrentLinkedQueue of WeakReferences. I have a thread-unsafe object that is pretty expensive to create, and most of the time it will ...
Juan Lopes's user avatar
4 votes
0 answers
1k views

C++11 generator implementation emulating Python's yield keyword

C++11's range-based loops allow convenient and easy iteration over containers, but what about more complicated iterations such as tree traversal? Usually this involves a lot of boilerplate code and ...
Lars Melchior's user avatar
3 votes
0 answers
229 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 ...
TDMR87's user avatar
  • 31
3 votes
0 answers
65 views

Concurrency control between a non-blocking and a blocking methods

In this program, there is a list of Holders that is managed by a singleton class. Each of the Holders keeps a copy of the ...
user1589188's user avatar
3 votes
0 answers
1k views

Create PDF preview

I have written the following GetPDFPreview() method. It open a PDF file, create a thumbnail (using PdfDocument class) and ...
tigrou's user avatar
  • 421
3 votes
0 answers
70 views

Partition numbers as polynomial, each number in a thread

I'm beginner at multithreading programming and I wanna write a piece of my code using it. I'm trying to split different numbers into multiple parts and store them as a polynomial. I wanna do this ...
HMD's user avatar
  • 151
3 votes
0 answers
3k views

Share data and mutexes across threads

I need a class that holds a huge amount of data, which should be useable across multiple threads. To avoid copying the data every time, I used a std::shared_ptr. To ...
AquilaRapax's user avatar
2 votes
0 answers
15 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
2 votes
0 answers
133 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
2 votes
0 answers
404 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: ...
z3nth10n's user avatar
  • 237
2 votes
0 answers
113 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....
user51515151's user avatar
2 votes
0 answers
87 views

Lock-free pooled queue

I am attempting to create a lock free pool of resources and I need the ability to access any one that is not already accessed and then return it back when I do not need it. This will happen very very ...
Christopher Silvas's user avatar
2 votes
0 answers
298 views

Mutex lock benchmark

I'm trying to measure how many CPU cycles a mutex lock takes. Can you find any problems in my mutex lock benchmark? ...
tuket's user avatar
  • 121
2 votes
0 answers
82 views

Comparing Java Semaphore versus ReentrantReadWriteLock

In this post, I attempted to compare the performance of two concurrency constructs: java.util.concurrent.Semaphore, ...
coderodde's user avatar
  • 27k
2 votes
0 answers
269 views

Thread-safe sensor interface with observer and strategy patterns

I have a thread-safe API for an observable Sensor. The concrete type of the Sensor is chosen in the ...
Philippe's user avatar
2 votes
0 answers
483 views

thread safe queue with interrupt function

I try to implement a thread safe queue with the interrupt function (interrupt all threads who are blocking to take data from queue). ...
szh's user avatar
  • 21
2 votes
0 answers
1k views

Thread-safe rand for C

I have this very short program for dealing with thread-safety of C's rand. Is it a correct implementation? ...
coderodde's user avatar
  • 27k
2 votes
0 answers
51 views

Asynchronous service that publishes a possibly infinite amount of events

I want to implement a service that fetches eyetracking events and publishes them to all subscribers of the stream. The whole thing is supposed to run asynchronously, so it doesn't block the UI thread. ...
Luca Fülbier's user avatar
2 votes
0 answers
66 views

Delay handling of registrations

I'm trying to solve the problem of a whiteboard receiving registrations before, during and after its own initialization. As each registration needs a bit of handling which can happen only after the ...
bowmore's user avatar
  • 5,359
2 votes
0 answers
94 views

Blocking Memory Queue

This is a FIFO blocking memory queue in F# to be used as a component in a logging library. ...
Lord Terabyte's user avatar
2 votes
0 answers
1k views

Dining philosophers using channels

I have the following code to solve dinning philosophers problem using Go channels and am looking for review comments: ...
coder_bro's user avatar
  • 419
2 votes
0 answers
1k views

Threadsafe Logger with scopetime logging

I wrote a Logger which uses the destruction of temporary objects to Log their values including a scope time logger. Lets see what i can improve here to increase the performance and everything else. <...
BennX's user avatar
  • 203
2 votes
0 answers
143 views

C++ (foreign) thread pool

I created a class which is some kind of thread pool. The difference is that it holds foreign threads. This means that the threads are created somewhere else and are then held by calling ...
Thomas Sparber's user avatar
2 votes
0 answers
103 views

Porting Java semaphore to MacOSX

I wanted to write some more JNI code and decided to (re)implement a semaphore for MacOSX. In order to assert somehow correctness of my implementation I hereby supply a (multi)consumer/(multi)producer ...
coderodde's user avatar
  • 27k
2 votes
0 answers
730 views

Simple multithreading and synchronization problems in MFC

I use a worker thread for some data processing in my MFC project. In the thread-controlling function, it needs to use some parameters (declared as member variables) to the data-processing. I use a sub-...
daiyue's user avatar
  • 129
2 votes
0 answers
102 views

D3D COM Object Pooling

I'm using the following pattern to pool D3D objects globally in my application. Is it a good idea (alternatives)? Is it thread-safe? ...
ronag's user avatar
  • 576
1 vote
0 answers
96 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
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 ...
Anonymous's user avatar
  • 111
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
1 vote
0 answers
160 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/...
Itay's user avatar
  • 11
1 vote
0 answers
76 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 ...
Anakhand's user avatar
  • 645
1 vote
0 answers
212 views

Near immutable, thread safe Builder

I'm writing a torrent streaming client. The plan is to wrap WebTorrent-cli and provide a Java interface to observe download state, cancel or pause downloads etc. Anyways, I came up with the following ...
Viplav Kumar's user avatar
1 vote
0 answers
71 views

C# asynchronous notification vector v2

As a result of my previous post, I have implemented / refactored my code and have started making successful use of my class. However I have come across a couple of new questions: The observer must ...
sfanjoy's user avatar
  • 233
1 vote
0 answers
288 views

Multithreaded FRC Robot Framework (Kinda Big)

I'm working on some code for an FRC Robot. I wanted to see if there's any obvious improvements that can be made here, that stands out, or stuff I should avoid doing. This is a test bed for the base ...
FailFTW's user avatar
  • 11
1 vote
0 answers
301 views

Thread-safe Java class for managing XML files <> domain models

This Java class (aka application component) role is to handle a series of XML files stored in the file system. It must convert those XML files to the corresponding application domain model, and it ...
LppEdd's user avatar
  • 121
1 vote
0 answers
124 views

thread safe queue with watermarks

A thread-safe queue suspending/resuming the producer when respectively upper/lower watermark has been crossed. Intended usage - interchange between a non-blocking IO loop thread and a consumer running ...
bobah's user avatar
  • 361
1 vote
0 answers
1k views

C++11 CLH Lock Implementation

As a hobbyist programmer I have been reading "The Art of Multiprocessor Programming" (Herlihy, Maurice; Shavit, Nir) and converting the Java spin locks into C++ - I have enjoyed this and learned a lot....
headwedge's user avatar
1 vote
0 answers
1k views

Retrieving localized Days of Week in PHP : setlocale VS IntlDateFormatter

I'm trying to find a good way to dynamically print a selection of localized days of week without resorting to an hard-coded array per language, leveraging locale mechanisms instead. Up until now, I'...
Jonathan Bérubé's user avatar
1 vote
0 answers
766 views

A semaphore implmentation with Peterson's N process algorithm

I need feedback on my code for following statement, am I on right path? Problem statement: Implement a semaphore class that has a private int and three public methods: init, wait and signal. The ...
June's user avatar
  • 11
1 vote
1 answer
72 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
0 votes
0 answers
105 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 ...
Bernardo1r's user avatar