Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
31 views

Comparing Java Semaphore versus ReentrantReadWriteLock

In this post, I attempted to compare the performance of two concurrency constructs: java.util.concurrent.Semaphore, ...
5
votes
1answer
68 views

C# asynchronous notification vector

The purpose of this class is to efficiently notify another thread when data is available with minimal blocking to access/pass the data. The data reader/producer thread processes data in bulk which ...
1
vote
1answer
52 views

Multithreading to allow multiple clients on to a server and client requests handling

I have to create a client-server JavaFX application using MVC which does many operations consisting mainly in messages exchange. I'd like to know if this way to handle client acceptance and client ...
1
vote
1answer
86 views

Java concurrency exercise, implementing transfer of amount from one account to another

This is in continuation with my synchronized implementation of a bank account in Java. I am trying to implement bank accounts repository and method to transfer money from one account to another. My ...
7
votes
2answers
790 views

Synchronized implementation of a bank account in Java

I am trying to implement a bank account with Java in a thread safe way. My code looks like: ...
0
votes
0answers
29 views

threaded event loop “interrupt” unit test without deadlocks

I have an event_loop implementation (basically an event/command queue and an exec function). I have added ...
5
votes
1answer
68 views

Implementation of thread-safe vector

I have implemented a thread safe vector, based on std::thread and std::vector. I am new to many of the patterns used in threading and was wondering if there's a more efficient way the locking can be ...
1
vote
0answers
48 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
2answers
48 views

Thread-safe singleton cache (Python)

In a service I'm developing I'm using three cloud services (five if you count additional two streaming services I have to create that are used by those cloud services in turn) and to orchestrate bits ...
0
votes
0answers
33 views

Spring Component Thread Safe

Recently I refactored an application to start using spring, and after some research, I found out that @Component is not thread safe. The class is this: (It's a converter from xlsx to json string) <...
1
vote
1answer
25 views

Spring TaskScheduling with HashMap

I am currently developing a Task Scheduler to run different methods at a certain time. In general it is a Spring-boot application an task execution/scheduling is just a very tiny piece of the whole ...
2
votes
0answers
39 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
63 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
1answer
60 views

Simple multithreading C project

I'm fairly new to C, and this is my first time using pthread. I am pretty sure I implemented it correctly, however I'd like to verify it is indeed executing the ...
2
votes
0answers
65 views

Repeating a task that may fail (in parallel)

Almost like this question here, I'm playing with some methods that may fail, but in my case, the method failing is not a exceptional case; it just means I need to try running it again. The method I'm ...
3
votes
0answers
60 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 ...
4
votes
3answers
109 views

Really easy synchronised access to an IEnumerable without boilerplate code

Often when reading data from a sequence (IEnumerable<T>) in multi-threaded code, a consistent snapshot needs to be taken inside a ...
5
votes
1answer
149 views

Linked list node-level locking

I am new to C++ threading library. I would love to get some comments on how to improve this code (if there are possible bugs, I would appreciate that feedback too). In particular, I want to refactor ...
1
vote
0answers
44 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 ...
7
votes
1answer
146 views

Threadsafe oneshot-event which fires on subscription if the event was fired in the past

Assumptions Basically, a Connection class has a "Disconnect" event. Subscribing to this event isn't thread-safe, because the disconnection may fire from another thread right before I subscribe. So ...
0
votes
1answer
820 views

Print odd and even numbers using two threads in Java

I was asked below question in an interview where I need to print out even and odd numbers using two threads so I came up with below code one without synchronization and other with synchronization. <...
1
vote
0answers
133 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
28 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 ...
3
votes
3answers
236 views

C++ upgradable RW lock implementation

I am using VS 2017 with C++ 17 standard set on Windows OS. What I'm missing in couple of heavily threaded projects is synchronizing mechanism that can be atomically upgraded from shared to exclusive ...
7
votes
4answers
673 views

Caching Color-Bitmaps as MemoryStreams

I am in the need to cache Bitmap's in a memory-optimized way because the API I am building will need to process many colored ...
1
vote
1answer
795 views

Static wrapper class for log4net Logging - thread safety

I'm using log4net in my application and have a static Log class which creates an instance of ...
1
vote
1answer
122 views

Run two computations in parallel, and return the results together

I am reading the "Learning Concurrent Programming in Scala" and there are exercises in the end of each chapter. One of exercises is Implement a parallel method which takes two computation blocks a ...
1
vote
1answer
168 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
311 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
79 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
606 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
134 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
788 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
64 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
649 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
254 views

Thread-safe cache using a linked list

Are the final templated functions allocate and deallocate thread safe? The Cache object is a ...
6
votes
1answer
1k 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
109 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 ...
5
votes
2answers
108 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
269 views

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

IReadOnlyCachedRepository<T> ...
5
votes
1answer
602 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
579 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
100 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 (...
3
votes
1answer
239 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
585 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
1k 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
98 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
449 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
56 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
185 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: ...