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.

Filter by
Sorted by
Tagged with
1
vote
1answer
296 views

Thread safe queue with buffer

I must implement thread-safe queue with buffer. According to the advice from the previous post: Thread-safe queue mechanism I resigned from Concurent Collections and used lock. Is it thread safe now? ...
-1
votes
1answer
451 views

Thread-safe queue mechanism

Is it my queue mechanism thread safe? I just wonder if I need concurrent collections. Need I lock Enqueue method? Console displays queue count in incorrect order, Does it affect on maxQueueCount at ...
2
votes
1answer
107 views

Synchronized template wrapper class

Issue: Code base has lots of data structures which are accessed between threads with >= 1 writer. Application logic becomes obfuscated due to lots of mutex locks. Solution: Create a template ...
9
votes
1answer
793 views

A thread-safe priority queue keeping its elements unique

This class is intended to be used in situations where queue.Queue does not suffice, because the following two properties are needed. Every item in the queue can ...
11
votes
1answer
145 views

C++ thread-safe averaging

Although having very little C++ experience, I was tasked to implement several statistics objects that are safe to be asynchronous accessed by different threads, that collect data in relatively small ...
3
votes
1answer
1k views

Simple rwlock implementation in c++11

For answering this question of stackoverflow I have written the code https://stackoverflow.com/questions/12033188/how-would-you-implement-your-own-reader-writer-lock-in-c11 Can someone review it - ...
3
votes
1answer
81 views

Java Concurrent Recursive API Access

I don't get to write multithreaded applications very often, so be gentle with my threads :-) I have an API input which contains a "score" and then a bunch of child nodes which also have scores, and ...
6
votes
2answers
971 views

Async Queue implementation without locking

I wrote a quick implementation of an async queue that utilizes a backing ConcurrentQueue. It was pretty much based on an implementation given in this Stack Overflow ...
4
votes
2answers
360 views

Thread-safe cache using a linked list

Are the final templated functions allocate and deallocate thread safe? The Cache object is a ...
7
votes
1answer
2k views

Getting serial port list

Needed to get a local serial port list. System.IO.Ports.SerialPort.GetPortNames() returns names but not the descriptions like you can see in Device Manager: ...
3
votes
1answer
172 views

Mutex helper for interprocess sychronization of accessing a network drive

I have two windows services working in parallel. Each of them is using a network drive that is connected and disconected dynamically by each one as required. They do it by executing ...
6
votes
2answers
166 views

Thread-Safe Garbage Collectible Memoizer

I am working on a little thread-safe, garbage collectible memoizer for Funcs in C#. The goals: Make it easy to Memoize deterministic functions. Make sure invocation of a memoized Func with a given ...
1
vote
1answer
376 views

Cached Repository that can refresh all or a subset of the data

IReadOnlyCachedRepository<T> ...
5
votes
1answer
758 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
2answers
835 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
1answer
115 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
3answers
777 views

Writing to file using TPL with ConcurrentQueue

Here is a sample code to explain the approach I am going for. ...
3
votes
1answer
342 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
1answer
814 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: ...
5
votes
1answer
2k 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 ...
3
votes
0answers
138 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 ...
9
votes
3answers
627 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
2answers
59 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
1answer
439 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: ...
2
votes
1answer
192 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
1answer
148 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
1answer
271 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
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 ...
3
votes
1answer
74 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
1answer
917 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
1answer
262 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
0answers
403 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
1answer
256 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
1answer
3k 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
0answers
331 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
2answers
489 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
1answer
198 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 ...
8
votes
1answer
4k 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
0answers
566 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 ...
2
votes
1answer
338 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
1answer
732 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
1answer
851 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
1answer
394 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
1answer
61 views
3
votes
1answer
154 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
1answer
681 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
1answer
1k 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
1answer
851 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
1answer
204 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 ...
7
votes
0answers
778 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 ...