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.

learn more… | top users | synonyms

4
votes
3answers
35 views

Lock-free SPMC queue

Here is my lock-free queue implementation for single producer with some preallocated memory. T is a simple type with no need for move operations. I don't use ...
4
votes
1answer
37 views

Parallelizing an algorithm with OpenMP using a dynamic work queue

I'm looking for comments on the design, correctness and performance (not so much style) of a dynamic work queue for OpenMP worker threads. I have an algorithm that can be thought of in terms of some ...
4
votes
1answer
144 views

Starting and stopping a thread for a command handler

I built an application class that should be runnable as a Thread and it would be nice to hear opinions of Java developers to improve my coding style. ...
7
votes
2answers
66 views

Updating resources while avoiding race conditions

I am writing a utility class for a game client. This class has two main functions: connect to a game server and retrieve the current game revision, and retrieve a "recipe", which is basically ...
3
votes
1answer
37 views

Queuing web service calls

Every call to the web service goes through a custom queuing system. This has a limit that is set to 1. Every call that enters the same time with another call is purged and not handled. Not sure if ...
4
votes
1answer
77 views

Calling a method in parallel which returns the future

I have an async method which calls my Task class while my Task class does all the work: ...
0
votes
0answers
34 views
4
votes
2answers
61 views

Disposable resource: lazy allocation

Background I'm writing a wrapper for a significant portion of a native library in Java. The native objects my classes are wrapping are giving me some headaches in terms of design. I'm not a fan of ...
0
votes
0answers
49 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. ...
3
votes
2answers
89 views

Windows Forms `ControlCollection` implementation

I've implemented my own version of the Control.ControlCollection class in System.Windows.Forms and obviously I want it reviewed. ...
3
votes
1answer
65 views

Generic ObjectCache with Expiration

I sometimes need an object that caches some data but only for the specified amount of time. So I created a class that should handle this. The main goal was to make it generic unlike the ...
8
votes
3answers
982 views

Simple generic double buffer pattern

I wrote a small generic implementation of a simple generic double buffer pattern, and I was wondering if it's actually thread safe or can be improved in any way. Note: The specific part that I'm ...
4
votes
1answer
92 views

C++ EventHandler Class

I need to have some thread-safe event handler (like C#'s EventHandler), so I made one. Here is my event handler class and sample code (compiled with VS2013). Is ...
2
votes
4answers
303 views

Implementing a thread safe log class with simple functionality

I have finally assembled an attempt to create a thread safe logging class and also ensured by file flags that file should not be accessed by different processes at same time. This classed will be ...
5
votes
2answers
1k views

Locking mechanism in C#

I would like you to review the locking mechanism I implement in C# class. Will it be working correctly with many threads? Please don't mind rest of the code because I just try to repair the class ...
4
votes
2answers
247 views

Thread-safe inventory system

I have implemented a thread safe inventory system. The Product is bound to a location in a warehouse. I have a Product class and ...
5
votes
2answers
869 views

Thread safe logging class in C# to use from DLL

I tried to sample up a logging class from this question and answer(I want to use this class from C# DLL). Made slight modification mainly to file name, and also how data is written. I am interested if ...
14
votes
1answer
604 views

Messed up Elevator Management System

In light of our current community-challenge I decided to build an Elevator Management System. Initially I intended to program the EMS like a real-time operating system and the elevators as ...
5
votes
1answer
139 views

Porting Java's synchronized() block to C++

I tried to create a class for porting Java's synchronized keyword to C++ using below code using *nix pthread's library. In general my test cases seem to work, but since this is a very critical topic ...
2
votes
1answer
60 views

Java “pulse” between threads

I have two threads. One runs a simulation and one runs a UI. In the UI, it is possible to trigger a "tick" of the simulation. There are a few constraints: Ticks run on the simulation thread Each ...
1
vote
1answer
103 views

Key Value Store for Android on top of Sqlite3

I wrote this simple key-value interface on top of Sqlite3 to use in my Android app. I am using this to persist Java objects as strings converted using Gson. The public API has 3 methods. ...
2
votes
1answer
44 views

Unreliable shared memory circular buffer with read-only consumer

This code is slightly platform dependent but should be pretty easy to port. The goal with this code was to create a circular buffer where the consumer could be limited to read-only access of the ...
4
votes
1answer
323 views

Layered architecture implementation in a Java web application

I am trying to learn how to design and implement a layered Java web application with a presentation layer, service layer and the DAO layer. I have used the Struts 1.3 framework with Java JDK 1.6 for ...
2
votes
0answers
49 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 ...
1
vote
1answer
191 views

Safely using android 'Context' inside threads

Oftentimes I find myself using context inside threads, multiple times. The problem is that I do not want to hold a long-lived strong reference of it in my threads to avoid leaking it. I keep a ...
4
votes
2answers
191 views

Thread-safe lock free FIFO queue

A few years ago there was a need to add a FIFO queue between 2 threads into my project. At that time I've got some interesting idea how to do that without any atomics and locks. (There was a ...
5
votes
2answers
310 views

Queue for distributing tasks between threads

I implemented the following class to dispatch std::function<void(void)> objects to a thread pool. Multiple threads will block on the pop call until a task is ...
2
votes
1answer
66 views

Thread-safe removewhere

I'm trying to implement a HashSet that it's accessed from different thread for querying, adding or deleting elements. It doesn't make sense to use a Dictionary for I got several search keys so I won't ...
4
votes
1answer
120 views

ConcurrentHashMap Implementation

I have written a simplified version of my own MyConcurrentHashMap. I tried to make use of a Lock[] array for ...
10
votes
2answers
118 views

Thread safety/Transaction enforcer

I have some legacy classes written without thread safety in mind. Instances of these classes are now being accessed in a multithreaded context in a thread-un-safe manner. Cue chaos. To fix this I ...
5
votes
0answers
206 views

Recursive shared_mutex implementation

I found myself in need of of a Readers-Writer mutex. With C++17 TR2 support not yet available in our compiler, I set out to implement std::shared_mutex so that we ...
5
votes
2answers
107 views

Blocking reads when writes are happening on two flows

I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write. My requirements are: Reads block until all three maps have been set for the first time. Now ...
3
votes
1answer
350 views

Thread-safe irregular rate limiter

Google's Guava library has a great RateLimiter, but I also needed a way to limit on an irregular basis, such as if an API I'm using has been throttled. I basically built a wrapper around Guava's ...
4
votes
1answer
44 views

Adding hostname to block list after x consecutive failures in multithreading application

I am using Callable in my code which will be called by multiple threads as shown below. Given a user id in DataKey object, I will find out what are the ...
7
votes
2answers
200 views

Thread-safe memoizer

I have searched around but I was not able to find a complete implementation of the memoize pattern in a multithreaded context. It's the first time playing with thread synchronization. The code seems ...
5
votes
1answer
119 views

Thread-Safe Variadic Printing Function

Printing to stdout is thread-safe in many systems when using printf or std::cout, but not in ...
4
votes
1answer
209 views

Refreshing customer list periodically in the background

I have a method RefreshCustomersInternal that refreshes customer data from a server and returns a Task. Since this process is ...
2
votes
3answers
619 views

Thread-safe Iterator wrapper

Aside: This code assumes a class Option that can be Some or None to represent the presence (Some) or absence (None) of the value it contains. Haskell calls it Maybe. Here is my first pass at ...
2
votes
0answers
122 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
1answer
89 views

Custom Session Pool

We use a student information system called Colleague that is developed by Ellucian. As far as I can tell, the system does not use any sort of session pool so rapidly opening and closing connections ...
6
votes
1answer
329 views

A thread-safe stop watch utility class

I am writing a stop watch utility class in Java that I want to be thread-safe (concurrent). Here is what I have right now: ...
13
votes
0answers
293 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 ...
2
votes
1answer
41 views

Safe Thread Synchronization

I think the following is thread safe. Am I right? How would you improve this code? Are there new APIs or methods I can use? Data: ...
4
votes
0answers
849 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 ...
3
votes
1answer
440 views

Simple thread-safe loading cache based on RxJava

I'm sketching a simple thread-safe cache which can load missing values. It is based on RxJava's Observable which also means that it should be possible for a client to join a request for value which is ...
4
votes
3answers
157 views

Thread safe cache for write through and writeback

This cache is like a list where new elements are inserted in the middle, cache hits are put to head of the list and replaced elements are taken from the end. Would I just use a list the lookup would ...
5
votes
2answers
392 views

Synchronization in an event manager

I'm working on an event manager, and I am wanting it to be a tool developers use. It is lightweight and it uses annotations to register events. I've tried to set up ...
3
votes
2answers
247 views

Thread Safe Objects in CSharp - ConcurrentDictionary

I'm using ConcurrentDictionary to hold the records.. I'm reading files from the local system in parallel, to speed up the process. Sample 1: ...
3
votes
1answer
1k views

Concurrent LRU cache using sychronizedMap() or ReadWriteLock

Trying to implement a simple, thread-safe LRU cache that's meant for "read mostly" use. Collections.sychronizedMap() Clean, simple, not much else to say. ...
2
votes
3answers
282 views

Thread safety and performance when multiple threads write into same Writer

Multiple threads write data to a file. When maxLines is reached, the file is closed and a new file is created: ...