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
2answers
63 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
113 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
57 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
59 views

ConcurrentHashMap Implementation

I have written a simplified version of my own MyConcurrentHashMap. I tried to make use of a Lock[] array for ...
8
votes
1answer
76 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
42 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 ...
4
votes
0answers
59 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
45 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
33 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 ...
6
votes
1answer
108 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
73 views

Thread-Safe Variadic Printing Function

Printing to stdout is thread-safe in many systems when using printf or std::cout, but not in ...
3
votes
0answers
60 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
203 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
64 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
67 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
143 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: ...
10
votes
0answers
201 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
40 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: ...
3
votes
0answers
239 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 ...
2
votes
1answer
176 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
105 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
197 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
154 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
279 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
82 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: ...
6
votes
1answer
237 views

Fast Thread- and multiprocess-safe file operations in python under Linux

I'm trying to implement an alternative to python built-in open(), but safe for use in multi-threaded and multiprocessing environment. I'm using advisory locking, ...
3
votes
2answers
223 views

Simple C++ thread pool

I wrote a minimalistic thread pool using some C++11 features. I've used it on two projects so far and it has worked fine, but when I ran the code on my laptop, I believe that my thread pool might be ...
4
votes
2answers
152 views

Simple concurrent freelist

To become better acquainted with the Intel Parallel Studio XE profilers I'm currently messing around with a simple concurrent freelist. I'm fairly certain that it's thread-safe. It uses Acq/Rel ...
3
votes
2answers
143 views

Is this a thread-safe implementation of background bitmap generation?

For a game implementation, I have a very large overview map with multiple layers (namely base-map / units / highlight & info / fov-shading) of which the first is CPU-intensive to generate. I have ...
2
votes
1answer
100 views

A thread-safe initialization guard

I have written a type with the following public API: ...
4
votes
1answer
81 views

C++11 lock free collection similar to std::forward_list - follow-up

Thread safe and lock free collections are very hard to write, so I'd appreciate any feedback, especially regarding bugs. The code below is a self contained cpp including some tests. This question is ...
4
votes
1answer
104 views

C++11 lock free collection similar to std::forward_list [closed]

I'm new to explicit memory ordering, and any kind of thread safety is hard to implement right to begin with. Please let me know if you see any problems, or have suggestions for improvement. Written in ...
1
vote
2answers
241 views

Updating list of string while others reading it in Java

I have a logging solution that writes down the hashes of messages. I consider some of these hashes to be safe and I want to skip logging those. I have implemented a whitelist that is a directory ...
1
vote
1answer
109 views
7
votes
3answers
2k views

Dining philosophers problem in C++11

Is this implementation correct? Do you find any threading problem? Also, what parts of the code can be changed to be more C++11-ish? ...
7
votes
1answer
239 views

Lock Using “Interlocked” vs lock Statement (“Monitor”) (Followup)

This is a followup to a previous question. Considering: Interlocked.CompareExchange generates a memory barrier, Intended to be used with very fast operations ...
4
votes
2answers
360 views

Lock Using “Interlocked” vs lock Statement (“Monitor”)

A followup question can be found here, based on this question and it's answer. Considering: Interlocked.CompareExchange generates a memory barrier, Intended to ...
4
votes
2answers
824 views

Running Code Just Once

I want a code run just once (say in Dispose). WriteOnceBlock<T> from TPL Data Flow could be used here; but again if we ...
3
votes
1answer
149 views

Ensure only a single instance of static template class member

I am interacting with a C library, whose documentation states that certain functions are not thread safe. Since its functions deal heterogeneously with multiple types, I have written a template ...
4
votes
1answer
195 views

Increasing performance and accuracy in multithreaded loop

I was wondering if the following set up will return consistent result, i.e. no thread function call will be skipped. Also, is there any way to improve the threaded loop? Note the first loop is the ...
3
votes
2answers
95 views

Typetokens in C++11

I have written a typetoken library in C++11 and I want to know if it is indeed typesafe, threadsafe and complete. The purpose of this library is to give an unique ID to every requested typename ...
6
votes
1answer
745 views

Efficiently using ZeroMQ sockets in Java

I am working on multithreading project and I am using ZeroMQ socket to send the data as a byte array. Below is my example which works fine. I'm opting for code review to see whether it can be improved ...
5
votes
2answers
657 views

Could I dispose IDisposable objects that are part of a Thread?

I have a question about using an IDisposable object in the ThreadStart function. I have a class that derives from ...
4
votes
2answers
397 views

Concurrent activity on ArrayList

I have an immutable Point class and a CollectionPoint class which manages instances of my ...
4
votes
1answer
331 views

Using concurrent dictionary as first-level cache

I am currently implementing a thread-safe in-memory cache mechanism, with the intent of storing objects that are expensive to create or often used by the system. I also want to include an expiration ...
5
votes
2answers
485 views

Extension methods for safely firing events

I wrote a set of extension methods for the EventHandler class that add the method Fire, which raises the event after creating a ...
4
votes
2answers
477 views

Performance of hashmap-based session object

Unfortunately, I can't use the Tomcat session for storing the key/value pairs for each user (restricted because it's an IVR domain-based project). But I need the same functionality like a ...
7
votes
3answers
276 views

Having full atomicity against all the threads without impacting performance or throughputs

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
3
votes
1answer
386 views

Loading GIF form on a Windows console app using threads

I have a main form which does processing for an extended period of time. Normally, progress bars are used to show either the loading status or simply show the program is still running/hasn't freezed. ...
3
votes
2answers
657 views

Thread-safe, in-memory LRU cache with a maximum item count of 10

I'm attempting to master LRU Caching. It must be thread safe, and it should preferably perform as well as web image-cache, (avg ~1MB). Please take a look to see if there's anything wrong, amiss, ...