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.
523
questions
1
vote
1
answer
655
views
Cached Repository that can refresh all or a subset of the data
IReadOnlyCachedRepository<T>
...
5
votes
1
answer
1k
views
Graceful thread shutdown with std::move [closed]
I have a thread as part of a class that access the class's data members. The class has a move constructor that moves some of the old class's data members into the new object being constructed. Before ...
4
votes
2
answers
2k
views
Object pool for allocating generic objects in aligned memory
I made a single header object pool for use in personal projects. It's supposed to be easy to use, cross-platform and thread safe. It uses a free list for allocations and a hashmap for dereferencing ...
6
votes
1
answer
292
views
Simple time-bound cache
In my project i should cache some items (1 - 1000) in one time.
Item should be removed from cache after 5 minutes by last access to cached item.
Better use community libs, or standart mechanisms (...
2
votes
3
answers
2k
views
Writing to file using TPL with ConcurrentQueue
Here is a sample code to explain the approach I am going for.
...
3
votes
1
answer
1k
views
Matchmaking for a multiplayer game
I have working code that needs some optimization for scalability and overall performance. This code basically creates a lobby where users wait for match to be created and link users for a multiplayer ...
1
vote
1
answer
2k
views
Thread Safe Evicting Queue in Java
Just wrote an Evicting Queue implementation, as an ordinary Linked List working under the hood, in Java; which, I hope, I've made thread safe, could you review?
Code:
...
6
votes
1
answer
5k
views
Process List asynchronously with SemaphoreSlim for throttling extension method
I've got some methods that follow a similar pattern, and wanted to abstract some of the logic away into an extension method. Specifically, I am processing lists of objects with the TPL, and throttling ...
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 ...
11
votes
3
answers
5k
views
C++ Threaded Logger
What is it?
It's a fairly simple logger which utilises a thread.
How it works
Note: this a pretty terrible explanation, perhaps it would be easier to look at the code.
The logger class is a ...
2
votes
2
answers
134
views
Fine-grained synchronization to serve a file
I'm writing a proxy server that serves cached resources. If resource is not cached, it's retrieved and put into filesystem. Server is multi-threaded and I want to avoid any kind of global locking. If ...
3
votes
1
answer
3k
views
Attempting to make my properties an enum based singleton
I was attempting to implement my first singleton using an enum, was a bit of a struggle for me and I'm not sure if its right and more importantly thread safe?
Property provider enum:
...
1
vote
1
answer
277
views
shared_instance implementation using C++ and RAII
I created a little singleton-like class that gets deleted when there is no reference to it anymore (so its lifetime shall be somewhat predictable). I aimed to make ...
7
votes
1
answer
387
views
A Game of Life application, with mouse clicks
I have a Game of Life program that has a grid[][] array which is populated by Cell objects. If there's a cell in a grid square, ...
6
votes
1
answer
282
views
Send records to messaging queue using either of one policy
I have bunch of keys (clientKey) and values (processBytes) that I want to send to our messaging queue by packing them in one ...
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 ...
3
votes
1
answer
142
views
Python 3 PriorityDeque with absolute priorities
Python 3 has queue.PriorityQueue, but that wasn't good enough (lacking methods, not double-ended, etc) for me and my purposes. Therefore, I have made a new one ...
1
vote
1
answer
2k
views
HttpClient wrapper for simple calls with optional cert
Trying to ensure each controller contains it's own httpclient. The super user can change which endpoint is called from the site and some of those endpoints do not require a certificate, but some ...
4
votes
1
answer
369
views
Send data synchronously or asynchronously
I am using below class to send data to our messaging queue by using socket either in a synchronous way or asynchronous way as ...
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....
3
votes
1
answer
276
views
Managing socket pool per datacenter
I have a list of sockets per datacenter (in general, I have around three datacenter and each datacenter having 20 sockets, so in total I have around 60 sockets). Now I have 20 business threads which ...
2
votes
1
answer
7k
views
Send data on a socket from multiple threads
I have around 60 sockets, 20 business threads and 1 pinger timer thread and I want to make sure each of those thread works on different socket every time so I don't want to share same socket between ...
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'...
5
votes
2
answers
674
views
The start of a Python port scanner
My concerns:
Is this module thread safe?
Is there any obvious performance issues I missed?
Is there a better container type to use for GENERATED_ADDRESSES other ...
2
votes
1
answer
346
views
Send records and retry them if acknowledgement is not received
I am using below class to send data to our messaging queue by using socket either in a synchronous way or asynchronous way as ...
11
votes
1
answer
9k
views
Concurrent HashSet
I've recently been using HashSet and locking on each method, I found this to not only be a lot of work (was using it in a lot of places) but I started to see inconsistency in my code.
I later decided ...
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 ...
1
vote
1
answer
3k
views
Replicate / Sync files from source to destination with powershell only
I have lots of live and disaster recovery servers, which should have the same files and folders. I searched on the web but could not find a Powershell script which has all of the functionality on the ...
1
vote
1
answer
2k
views
Dining Philosopher's problem implementation with Java Locking Framework to avoid deadlock
Dining philosopher problem is one of the classic problems in computer science. I intended to implement it using Java threads. I attempted using the locking framework that came with Java 5 and used the ...
1
vote
1
answer
1k
views
Singleton with a volatile and synchronized instance
I created a singleton to have a unique instance of ExecutorService in my application.
I whould like to know which is the better of the two classes below.
First one :
...
1
vote
1
answer
1k
views
Synchronized Queue Wrapper C++11
I am trying to write a SynchronizedQueue wrapper class to provide a simple synchronized interface to underlying standard ...
0
votes
1
answer
205
views
3
votes
1
answer
401
views
Generic oneshot task runner
I'm making some helper functions for the (fairly simple) UI framework I'm developing, among them, a helper to run app initialization tasks. Here's a helper class I've developed for oneshot tasks:
<...
3
votes
1
answer
2k
views
Custom setInterval to run function synchronously
This customSetInterval function makes sure that the function inside it is executed synchronously. It also gives that function the ability to determine run or stop ...
11
votes
1
answer
2k
views
Do not share same socket between two threads at the same time
I have a code in which I am dealing with sockets and I need to make sure that I don't share same socket between two threads. In my below code, I have a background thread which runs every 60 seconds ...
2
votes
1
answer
3k
views
Thread safe algorithm for arrays information manipulation
I have a program which requires a usage of threads and it must be thread safe. I do not have much experience with threads and critical sections, but as much as I know you must lock code sections where ...
1
vote
1
answer
557
views
Heartbeat Server
I'm writing a toy heartbeat server. Each client, upon loading, registers itself and thereafter, sends heartbeats every X seconds. The server checks every ...
15
votes
1
answer
1k
views
C++11 Threadpool
I have developed a threadpool using the standard c++11 features and am looking for feedback.
Right now I think the implementation is pretty solid, but as I recently learned about multithreading I'm ...
0
votes
1
answer
518
views
Singleton design pattern study
I am learning design patterns and the singleton is one of them. What are your opinions on the code? Please feel free to share.
I know singletons are not popular because of complications in testing. I ...
5
votes
1
answer
1k
views
Dining Philosopher correctness
How should I improve my solution for Dining Philosopher's problem?
...
3
votes
1
answer
3k
views
Thread safe tbb::concurrent_hash_map and std::set
I have a basic websocket server implemented in C++. I'm using Intel TBB's concurrent hash_map to store all the users, uniquely identified by the id. The concurrent ...
1
vote
1
answer
3k
views
Yet Another multithreaded FIFO queue written in C++17
Here, I have written a simple FIFO multithreaded queue with following features (if I have implemented correctly):
Thread safe
Supports multiple container types (given that they provide some function) ...
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?
...
4
votes
1
answer
537
views
ThreadPool implementation in C++
I have written a simple thread-pool implementation in C++ and want your comments to improve my understanding and improve my implementation. I understand I am repeating thread-pool implementation, but ...
1
vote
3
answers
2k
views
Simple counting fair semaphore implementation
Here is my attempt to implement a simple counting semaphore in Java. Please share your comments.
...
5
votes
2
answers
612
views
Thread-safe BitArray
Notes:
supports 64-bit platforms only
ulong used where negative values make no sense
library functions are assumed to be correct (whether they actually do what I ...
2
votes
1
answer
2k
views
Stopping a thread that runs an action periodically
I have a class that (among others) needs to run an action at fixed intervals of time. So I created a thread for this:
...
9
votes
1
answer
1k
views
Dynamically extensible threadpool implementation in C
Purpose
For my recent project, I needed a thread pool. I saw a lot of implementations at GitHub, but most of them were quite complicated. With complication comes performance penalty. Most importantly,...
6
votes
1
answer
2k
views
Thread safe ConcurrentDictionary wrapper
I needed some features that ConcurrentDictionary doesn't have (such as a maximum number of items) so I created a wrapper around it.
This is my first time working ...
4
votes
2
answers
5k
views
C++ minimal threadsafe array based on std::deque
Here is a minimal example of a threadsafe array I want to build on for a timeseries application, with the following characteristics:
Ever-growing, and the already contained elements remain constant
(...