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.

1
vote
0answers
16 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
36 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
24 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
23 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
36 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
46 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). ...
1
vote
1answer
42 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
61 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
55 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
107 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
109 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
36 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
133 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
361 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
130 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
27 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
185 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
657 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
563 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
96 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
134 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
260 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
69 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
538 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
129 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
638 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
60 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
442 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
211 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
843 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
88 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
94 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
205 views

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

IReadOnlyCachedRepository<T> ...
5
votes
1answer
511 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
449 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
92 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
206 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
492 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: ...
0
votes
0answers
19 views

In Multi threaded environment, execute same group tasks in linear

Problem Statement: There will be a lot of requests to do a specific type of operation with different parameters. We have to do execution in parallel but In one scenario where operation from same ...
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
69 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
392 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
51 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
151 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: ...
3
votes
1answer
142 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 ...
8
votes
1answer
107 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
259 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
66 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
60 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
620 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 ...