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 (1)

6
votes
5answers
819 views

A buffer that holds and provides the latest n items

I have developed the following code to hold n latest items it has received, and when asked for provide these n latest items. The interface is: ...
3
votes
2answers
49 views

Make all additional threads return from a method using Interlocked.Increment

I need to ensure a method is executed only by one thread at a time. Contrary to what most of the synchronization primitives do, I don't need other threads to wait, I want them to return from the ...
6
votes
2answers
263 views

Simple dispatcher implementation

I need a simple dispatcher implementation(invoke methods on one thread from many threads) once you dispatch method curent thread should wait for results, so I'm thinking about something like this: <...
0
votes
1answer
30 views

How to avoid carrying around a lock with my variable when multiple threads instantiation in Python?

I created an application using multiple threads defined in multiple class files which read and write into a "shared variable" (a dictionary). To ensure thread-safety, I am using a Lock, and I pass it ...
2
votes
2answers
144 views

Thread synchronization wait/notify

I need to run several identical threads. All threads must wait to do their job, until all threads are running (alive). I use wait/notify to synchronize: when a thread is created it waits until it ...
2
votes
2answers
93 views

Concurrent bidirectional dictionary

I've been agonizing over this for an hour or two. I require a bidirectional dictionary that was thread safe. From what I understand about dictionaries, they're thread safe when being read from, but no ...
0
votes
2answers
99 views

Java synchronization task

I have the following task: Implement a simple command line Java application for booking bus seats. For simplicity suppose there is only one bus, initially all seats (lets say 50) are free. ...
5
votes
1answer
158 views

Simple Background Thread Worker Class (follow-up)

This is a follow up of Simple, generic background thread worker class What changed? Moved from synchronized lazily evaluated static instances to true Singletons per the on-demand holder idiom https:...
0
votes
0answers
43 views

Block a partcular machine for a particular period of time interval after x failure

This is an extension to this question I am working on a library which makes Http call to my service. I have below two requirements: If my service machine doesn't respond back (there is a socket ...
5
votes
1answer
68 views

Server connection handler in Python

I am working on a server for a smart house. This part of code is responsible for communication with client (separate application), sending requested data and ensuring everything is safe. I've decided ...
1
vote
1answer
53 views

Pipeline with std::thread vectors and queue

here is my code, it works but after few iterations it slows down and stop without any error, I'm looking for a more efficient solution. ...
2
votes
1answer
144 views

Portable periodic/one-shot timer thread - follow-up

This is a much improved version (I hope) of code in this previous code review of mine. I have: renamed several things. Are the names good? made it lazily start the worker thread only after the ...
2
votes
1answer
38 views

Thread-safe Bloom Filter in Java

I have tried to implement a Bloom Filter in Java here. https://github.com/srirammanoj/skynet/tree/master/bloomfilter I just wanted to know if my implementation can be called 'thread-safe' , and if ...
1
vote
0answers
18 views

Passive FTP port assignment synchronization

I've created the following class to manage the assignment of port numbers to passive FTP server sockets. Notice that Semaphore here is to make the thread wait in ...
3
votes
2answers
50 views

Thread Safe Servlet

I am working on a JSP MVC web application. I am confused about Thread-Safe Servlet concept. Following is my code, please tell me is it thread safe or not. Also, tell me the reason that why it is ...
2
votes
0answers
34 views

Delay handling of registrations

I'm trying to solve the problem of a whiteboard receiving registrations before, during and after its own initialization. As each registration needs a bit of handling which can happen only after the ...
1
vote
1answer
83 views

Simple type-safe and thread-safe Rust event system

I'm creating a relatively simple type-safe and thread-safe Rust event system. It is to be used with and within an IRC library I'm making, but should work just fine for other use-cases. It needs to be ...
1
vote
1answer
73 views

Telegram - GetUpdates Process

My code fetches telegrams from a server periodically in the background. The server API is documented here. What do you think of the way I do multithreading by handling my ...
1
vote
1answer
161 views

Thread safe REST API

My assignment was to develop a REST service that will provide Airport information. This service is assumed to be used by multiple users, therefore data consistency (thread safety) and responding fast ...
3
votes
1answer
34 views

Synchronization of new data with previous data

I am working with synchronization for the first time. I wrote some code that I have to implement in my current work. I wanted to know if I am doing it right or am I making a mistake. Whenever a new ...
3
votes
2answers
132 views

Queuing e-mail notifications in a background thread

I'm new to parallel programming concepts. I'm trying to implement fire-and-forgot kind of method in my project. Somebody please evaluate the below code & let me whether this is thread safe or not. ...
0
votes
1answer
35 views

Loading message with Pthreads

I want to print a nice loading message with these three fading dots, while the main thread does some heavy IO stuff. This is why I implemented this: ...
2
votes
0answers
69 views

Blocking Memory Queue

This is a FIFO blocking memory queue in F# to be used as a component in a logging library. ...
4
votes
1answer
73 views

Simple worker class

I just wrote a basic worker class for this person http://stackoverflow.com/questions/35827459/assigning-a-new-task-to-a-thread-after-the-thread-completes-in-c and I wanted to ask if the code has ...
1
vote
1answer
113 views

Implementing the Actor-Model in C#

After learning the basics (isolated state, communication and computation) of the the Actor-Model, I wrote my own implementation and I'm ready for a thorough code review. You will be able to see that ...
1
vote
1answer
32 views

Hibernate Save method practice

We are new into hibernate, in our project for saving an entry the below given code is used, please have a look. ...
4
votes
3answers
111 views

Lock-free SPMC queue

Here is my lock-free queue implementation for single producer with some preallocated memory. T is a simple type with no need for move operations. I don't use ...
5
votes
0answers
128 views

Parallelizing an algorithm with OpenMP using a dynamic work queue

I'm looking for comments on the design, correctness and performance (not so much style) of a dynamic work queue for OpenMP worker threads. I have an algorithm that can be thought of in terms of some ...
4
votes
1answer
219 views

Starting and stopping a thread for a command handler

I built an application class that should be runnable as a Thread and it would be nice to hear opinions of Java developers to improve my coding style. ...
1
vote
3answers
272 views

Implementing an asynchronous mutex in C#

I wrote a simple synchronization primitive that I can use with async operations on an external REST service so that I don't call it twice from different threads and have one call fail due to not ...
7
votes
2answers
79 views

Updating resources while avoiding race conditions

I am writing a utility class for a game client. This class has two main functions: connect to a game server and retrieve the current game revision, and retrieve a "recipe", which is basically ...
3
votes
1answer
95 views

Queuing web service calls

Every call to the web service goes through a custom queuing system. This has a limit that is set to 1. Every call that enters the same time with another call is purged and not handled. Not sure if ...
4
votes
1answer
117 views

Calling a method in parallel which returns the future

I have an async method which calls my Task class while my Task class does all the work: ...
1
vote
0answers
87 views

Dining philosophers using channels

I have the following code to solve dinning philosophers problem using Go channels and am looking for review comments: ...
3
votes
1answer
60 views

Synchronization algorithm for deterministic context switching between threads

Curious how sqlite3 would handle different race conditions in a multithreaded environment, I created a simple module called deterministic for serializing the ...
0
votes
0answers
64 views
4
votes
2answers
98 views

Disposable resource: lazy allocation

Background I'm writing a wrapper for a significant portion of a native library in Java. The native objects my classes are wrapping are giving me some headaches in terms of design. I'm not a fan of ...
0
votes
0answers
128 views

Threadsafe Logger with scopetime logging

I wrote a Logger which uses the destruction of temporary objects to Log their values including a scope time logger. Lets see what i can improve here to increase the performance and everything else. <...
2
votes
1answer
86 views

Multithreading, shared queue as synchronization point

I have two threads, one produces images and one processes them. For the synchronization, I created a class where you can set and get images, and it always waits until an image is available or a worker ...
3
votes
2answers
218 views

Windows Forms `ControlCollection` implementation

I've implemented my own version of the Control.ControlCollection class in System.Windows.Forms and obviously I want it reviewed. ...
3
votes
1answer
93 views

Generic ObjectCache with Expiration

I sometimes need an object that caches some data but only for the specified amount of time. So I created a class that should handle this. The main goal was to make it generic unlike the ...
8
votes
3answers
1k views

Simple generic double buffer pattern

I wrote a small generic implementation of a simple generic double buffer pattern, and I was wondering if it's actually thread safe or can be improved in any way. Note: The specific part that I'm ...
4
votes
1answer
140 views

C++ EventHandler Class

I need to have some thread-safe event handler (like C#'s EventHandler), so I made one. Here is my event handler class and sample code (compiled with VS2013). Is ...
2
votes
4answers
402 views

Implementing a thread safe log class with simple functionality

I have finally assembled an attempt to create a thread safe logging class and also ensured by file flags that file should not be accessed by different processes at same time. This classed will be ...
5
votes
2answers
1k views

Locking mechanism in C#

I would like you to review the locking mechanism I implement in C# class. Will it be working correctly with many threads? Please don't mind rest of the code because I just try to repair the class ...
4
votes
2answers
434 views

Thread-safe inventory system

I have implemented a thread safe inventory system. The Product is bound to a location in a warehouse. I have a Product class and ...
5
votes
2answers
2k views

Thread safe logging class in C# to use from DLL

I tried to sample up a logging class from this question and answer(I want to use this class from C# DLL). Made slight modification mainly to file name, and also how data is written. I am interested if ...
16
votes
1answer
685 views

Messed up Elevator Management System

In light of our current community-challenge I decided to build an Elevator Management System. Initially I intended to program the EMS like a real-time operating system and the elevators as finite-...
5
votes
1answer
290 views

Porting Java's synchronized() block to C++

I tried to create a class for porting Java's synchronized keyword to C++ using below code using *nix pthread's library. In general my test cases seem to work, but since this is a very critical topic ...
2
votes
1answer
67 views

Java “pulse” between threads

I have two threads. One runs a simulation and one runs a UI. In the UI, it is possible to trigger a "tick" of the simulation. There are a few constraints: Ticks run on the simulation thread Each ...