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

4
votes
1answer
70 views

Pre-Java 5 threads

I would like to revise the fundamentals of Java threads on before-Java 5, so that I can understand improvements in Java 5 and beyond. I started off with a custom collection and need help on: Things ...
5
votes
1answer
42 views

CountdownLatch: Is this thread-safe?

I am trying to learn how to write correct lock-free code. I've written this class out of exercise for a synchronization construct to be used across multiple threads. The intent is to have worker ...
2
votes
0answers
24 views

OpenMP parallel for critical section and use of flush

The following is my code. I am not sure about the place where flush should be used (if it is used at all here). ...
2
votes
1answer
40 views

OpenMP loop parallel for loop with function calls and STL vector

I have a function initialize_path_statistics(). I have used openMP to make it parallel. I am not sure where certain lines such as ...
2
votes
1answer
46 views

Decoding big text input: potential concurrency bugs?

The code here will be directly pasted from this project. Quick summary: it is related to a Stack Overflow question. So, basically, all the code below aims to implement ...
9
votes
2answers
106 views

Is this use of a resource based on session ids thread safe?

Let me first describe the expected behavior of the code below: There will be one static SessionManager accessed by many threads. Multiple calls to ...
4
votes
1answer
42 views

Correctly implementing the Swing TreeModel

Ideally the Code Review would target the correctness of the approach implementing the Swing TreeModel. In particular, is the structural separation[1], event message passing, threading[2], object ...
2
votes
0answers
89 views

Is my threading design okay or not?

I am new to threading and I am a junior developer, so I guess there are many mistakes. My scenario is this: look into the database if there are data which should be sent add the data to the queue ...
0
votes
1answer
61 views

Threadsafe network message

I have started making a very basic networking library in C++. It is built on UDP, with both reliable and unreliable delivery options. So far, I have made the base messaging class, so I will show the ...
4
votes
2answers
135 views

Using threads to find max in array

I really do not have access to anyone, outside of professors, that is highly knowledgeable about Java so I figured I would post my stuff here to further my knowledge and improve my coding. This is ...
7
votes
3answers
127 views

ConcurrentThrottledList - Will this implementation be thread safe?

I want a thread safe list with a max item count, will the following implementation correctly provide this? ...
4
votes
2answers
249 views

A TaskScheduler that always run tasks in a specific thread

The following is an TaskScheduler that always run tasks in a thread it maintains. When created, a name of the thread was specified. Once you schedule the first ...
10
votes
2answers
130 views

Thread-safe prime number source

I am working on some multi-threaded code that requires a prime-number source. The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being ...
5
votes
2answers
85 views

Am I using Lazy initialization properly?

The following code is intended to implement a LinFu DynamicProxy interceptor to lazy load given virtual properties from an Umbraco datastore. My concerns: Thread safety, Have I covered all the ...
5
votes
1answer
63 views

What is a safe way to lock a thread in a single-threaded application?

I was looking at the different possible threading methods that I could use in my single-threaded application. What I have written so far is a class that will lock the thread when I instantiate the ...
4
votes
2answers
88 views

Long Thread & EDT

I’m trying to make a simple gui app that starts a “long” process that can be started and stopped. The process generates random numbers and displays them in a JList. As numbers are being displayed ...
2
votes
1answer
47 views

Run the most recently requested action after finishing current, skip middle tasks

The goals for the code below are in the class summary below. Can anyone see that the code fails at any of those goals? I'm unsure how to thoroughly test it. Is there a way to keep the Queue method ...
5
votes
3answers
111 views

Feedback on thread safety of the classes

I have following classes. Are they properly guarded for thread safety? Do you see any issues with any of the classes? ...
9
votes
1answer
668 views

Thread-safe concurrent FIFO queue in C++

Is this the correct way to implement a thread-safe concurrent FIFO queue in C++? It requires passing unsigned char* arrays of binary data. Thread Safe Concurrent ...
5
votes
2answers
308 views

Simple thread pool in C++

I wrote a simple thread pool, which works pretty well. I would like to see your review of it. One important feature that I needed in the pool is the ability to wait until all the tasks that I sent to ...
1
vote
2answers
95 views

Is that correct example of unsafe publication in java? [closed]

There are many examples of unsafe publication on the web. But I cannot find a complete program for reproducing it. I wrote an example but I do not sure whether it correct or not. And in case of ...
6
votes
1answer
80 views

Allow changing the properties of a mutable controller in a thread safe way

I have a (control engineering) controller. These controllers usually need several parameters to do their thing, and in my application it is desirable that these parameters can be changed while the ...
3
votes
1answer
144 views

How to avoid GSON deserialization if I am aware of error response from the server?

I am working on a project in which I am making a call to one of my servers using RestTemplate which is running a restful service and getting the response back from ...
3
votes
1answer
104 views

How to make builder pattern thread safe in the multithreading environment?

I am working on a project in which I need to have synchronous and asynchronous method of my java client. Some customer will call synchronous and some customer will call asynchronous method of my java ...
7
votes
1answer
198 views

Using keywords async/await in database queries (Windows Phone 8)

I have a local database in Windows Phone 8 app. The app includes a lot of queries to the database and I don't want bad effect on the responsiveness of UI. For ...
8
votes
1answer
126 views

Is this a true Multiton and is it thread safe

See WikiPedia - Multiton Pattern for details on the intent. Here's the class: ...
10
votes
2answers
365 views

Abuse/Misuse of C# BackgroundWorker?

I have finished a program, and it does what I want it to do, but I feel I am "doing it wrong", even though it's seemingly efficient enough. I have prepared a small example of what I feel I am handling ...
3
votes
1answer
43 views

Invoke only by a single thread

I wrote a simple class in Python, which controls code invocation, in a multi-threaded environment, with the following logic: The class' main method, named ...
5
votes
1answer
200 views

How to make this function thread-safe?

I have an array that I want to enumerate using blocks concurrently. However, I'm having trouble making this thread safe. I am new to using blocks and locks, so I am hoping someone may be able to push ...
5
votes
2answers
220 views

Efficient way of having synchronous and asynchronous behavior in an application

I am working on a project in which I am supposed to make synchronous and asynchronous behavior of my client. In general, how our client will work as below - Customer will call our client with a ...
4
votes
1answer
165 views

Thread safe class

The following class's method public IAsyncResult BeginInvoke(Delegate method, object[] args) is called by a third party dll. This dll may or may not be ...
2
votes
1answer
149 views

A Spring + GWT + Jetty + Gradle application

I just created a sample project using Spring 3.x, Jetty 9.x, GWT 2.5.1 and Gradle - https://github.com/krishnaraj/JettyGwtSpringSample. Its a slightly modified version of the 'Greeting' gwt ...
4
votes
1answer
331 views

simple ThreadPool implementations

I would like to ask you for a code review of my c++11 Thread Pool implementation. Your constructive criticism is welcome! Could you give me some ideas how to extend it? The main idea is to ...
2
votes
1answer
336 views

Multithreaded horse race simulation

I'm just starting to get along with threads in Java and I need some code review, about interfaces, classes, managing threads, correct writing, secure threads, exposed objects etc. Horse-Race ...
6
votes
4answers
147 views

Valid and safe use of SpinLock in Singleton?

Is this a valid and safe use of .NET's System.Threading.SpinLock? Why am I doing this? Random's public methods are not ...
2
votes
1answer
767 views

Thread safe enqueue and dequeue method in Queue

As an exercise, I have implemented a linked queue whose enqueue and dequeue methods are synchronized. There is a ...
6
votes
4answers
309 views

Organizing semaphores into a pyramid

My homework was to organize semaphores into a pyramid. The task was accomplished, but I ended up with this long ugly conditional and was wondering if anyone can see a better way/algorithm to ...
2
votes
2answers
132 views

Is this the right way to thread-protect an object?

I wrote an FAQ on a third-party website which pertains to thread-protecting objects in Delphi. What I'd like to know is if this thread-protection approach is accurate, or if I should change anything ...
4
votes
2answers
385 views

Thread-safe linked list review

I want to implement a thread-safe singly linked list in C. Its nodes contain unique entries and I only need functions to add nodes (to head only), remove nodes and to locate a specific node. I am ...
6
votes
2answers
278 views

Is this code thread-safe?

EDIT: The full source code in question can be found here. Is this code reasonably safe against dead/livelocks, and if not, how can I fix it? I know processes are usually recommended over threads ...
1
vote
2answers
412 views

Static classes, singleton and thread-safety

I have a classes for work with a web service (Windows Phone 8 app). I will briefly describe what doing each. My main question is the thread-safety of the ...
1
vote
2answers
135 views

Synchronized block over concurrent collections

This is the old code: ...
2
votes
3answers
198 views

Java - Unbounded, High-performance(?), Generic, Thread-Safe(?), BatchedCircularQueue

This is my first CodeReview question. I think I'm doing this right... Anyway, this is a data structure I wrote: It is an circular first-in-first-out queue (a ringbuffer); It has batched ...
1
vote
1answer
152 views

Calling different bundles in parallel using ExecutorService

I am working on a project in which I will be having different Bundles. Let's take an example, Suppose I have 5 Bundles and each of those bundles will have a method name ...
1
vote
2answers
164 views

Thread safe object pool, is this object pool thread safe?

If many threads Borrow() and Return() an instance of Packet from/to PacketPool could the Exception in Packet.Init() ever be thrown? Assuming only PacketPool ever called the Init() and UnInit() methods ...
2
votes
2answers
1k views

Thread safe message queue without mutex in C

I'm trying to write a message queue implementation so my threads can exchange data. To keep things simple, the queue is only responsible for sending pointers to memory. Only one thread may send ...
5
votes
1answer
443 views

Class to encapsulate and manage multiple background web crawlers

I need to crawl web contents from some websites and then do some processing. Note that this is a small application, so the dataset is relatively small (need to crawl about 30,000 pages every time, ...
2
votes
1answer
171 views

Is this actually thread safe?

I wrote this class to ensure that anything done in any of my worker threads can be displayed on the GUI via events, but i ran into non-thread-safe problems. This class should take a action with zero ...
2
votes
1answer
152 views

Review: custom, simple cache with load timeout and expiry; thread safety, tests: can I do better?

The following is a code from one of my projects which implements a loading cache with timeout and expiry. The associated tests are here (mixed with a good number of argument sanity checks tests). I ...