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.

52 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
29
votes
0answers
888 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
7
votes
0answers
797 views

C++11 Threadpool

I developed a threadpool using the standard c++11 features and was looking for feedback! Right now I think the implementation is pretty solid, but as I recently learned about multithreading I'm not ...
5
votes
0answers
84 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 ...
5
votes
0answers
121 views

Semaphore implementation by file locking in a bash script

This implementation is inspired by the POSIX functions sem_wait() and sem_post(). It tries to get rid of busy loops in the code ...
5
votes
0answers
6k views

Timeout watchdog using a standby thread

The simple but generic timeout class to be used watching for network connections, user input, filesystem events, and is intended to have a very simple interface specific to only our use cases (i.e. no ...
4
votes
0answers
96 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 ...
4
votes
0answers
77 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 ...
4
votes
0answers
233 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 ...
4
votes
0answers
70 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 ...
3
votes
0answers
37 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 ...
3
votes
0answers
148 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 ...
3
votes
0answers
1k views

Create PDF preview

I have written the following GetPDFPreview() method. It open a PDF file, create a thumbnail (using PdfDocument class) and ...
3
votes
0answers
54 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 ...
3
votes
0answers
946 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 ...
2
votes
0answers
36 views

SharedPreferences singleton wrapper

I was wondering wether my implementation of the PreferenceService below is thread safe or could cause memory leaks. Android Studio gives me the warning "Do not place Android context classes in ...
2
votes
0answers
65 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 ...
2
votes
0answers
50 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? ...
2
votes
0answers
36 views

Comparing Java Semaphore versus ReentrantReadWriteLock

In this post, I attempted to compare the performance of two concurrency constructs: java.util.concurrent.Semaphore, ...
2
votes
0answers
55 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 ...
2
votes
0answers
159 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). ...
2
votes
0answers
616 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? ...
2
votes
0answers
46 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. ...
2
votes
0answers
39 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 ...
2
votes
0answers
85 views

Blocking Memory Queue

This is a FIFO blocking memory queue in F# to be used as a component in a logging library. ...
2
votes
0answers
942 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. <...
2
votes
0answers
131 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 ...
2
votes
0answers
2k 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 ...
2
votes
0answers
93 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 ...
2
votes
0answers
655 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-...
2
votes
0answers
96 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? ...
1
vote
0answers
54 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 ...
1
vote
0answers
48 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 ...
1
vote
0answers
143 views

An attempt of replacing CRITICAL_SECTION with std::mutex and std::lock_guard

I have an older class that I am working on and I'm updating it to remove "Windows" specific code. It had some "Thread Protection Code" that used CRITICAL_SECTION. I'...
1
vote
0answers
61 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 ...
1
vote
0answers
150 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 ...
1
vote
0answers
36 views

Drawing sprites and adding new ones

I have some code that draws sprites and and allows new ones to be added. To do this, I use 2 lists: 1 for the sprites that need to be drawn, and one for the new sprites that need to be added to the ...
1
vote
0answers
91 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 ...
1
vote
0answers
435 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....
1
vote
0answers
341 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'...
1
vote
0answers
577 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 ...
1
vote
0answers
191 views

Singleton lock for a queue

This is a singleton class which can be accessed anywhere including the shouldLock variable. I want to make sure that the variable is thread safe. Basically the <...
1
vote
0answers
122 views

Thread safe scene graph

Below is my implementation of a thread safe scene graph; I'd love some feedback, especially regarding safety and efficiency. The key pieces are deferring node deletion until a single threaded portion ...
1
vote
0answers
76 views

Synchronous cinema hall, with StampedLock

I'm beginner in Java concurrency mechanism. I wrote some application to train a synchronization between many threads. I noticed that I wrote a lot of if statements, and it looks really ugly. Maby is ...
1
vote
0answers
41 views

How to ensure there is one Executor

I am using Socket.IO-java on the desktop application to handle realtime communication with the server. I was wondering if I could get some feed back on the setup as I am not happy with how it's done, ...
1
vote
0answers
81 views

Safe locking, replaced thread by task inside Job Manager

I replaced the thread by a task so there's no thread locked when there is no job to execute for hours. Now i'm not sure if the lock without an AutoResetEvent is lock safe when AllowParallelExcuteion ...
1
vote
0answers
354 views

Combination of Java's Future and Android's AsyncTask

My goal is create a class which implements Future interface of Java (get, cancel, isDone...), yet provides callback like ...
1
vote
0answers
56 views

Block a partcular machine for a particular period of time interval after x failure

This is an extension to this question I am working on a library which makes Http call to my service. I have below two requirements: If my service machine doesn't respond back (there is a socket ...
1
vote
0answers
29 views

Passive FTP port assignment synchronization

I've created the following class to manage the assignment of port numbers to passive FTP server sockets. Notice that Semaphore here is to make the thread wait in ...
1
vote
0answers
648 views

Dining philosophers using channels

I have the following code to solve dinning philosophers problem using Go channels and am looking for review comments: ...
1
vote
0answers
300 views

Synchronize access to an instance method using a static serial queue

In my current project I have a number of data services classes, each one dedicated to a specific source of data so that it's responsible of downloading data from its API, checking for local database ...