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
2answers
139 views

Concurrent activity on ArrayList

I have an immutable Point class and a CollectionPoint class which manages instances of my ...
4
votes
1answer
46 views

Using Concurrent Dictionary as First Level Cache

I am currently implementing a thread safe in memory cache mechanism, with the intent of storing objects that are expensive to create or often used by the system. I also want to include expiration ...
5
votes
2answers
83 views

Extension methods for safely firing events

I wrote a set of extension methods for the EventHandler class that add the method Fire, which raises the event after creating a ...
4
votes
2answers
161 views

Performance of hashmap-based session object

Unfortunately, I can't use the Tomcat session for storing the key/value pairs for each user (restricted because it's an IVR domain-based project). But I need the same functionality like a ...
7
votes
3answers
253 views

Having full atomicity against all the threads without impacting performance or throughputs

I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
3
votes
1answer
105 views

Loading GIF form on a Windows console app using threads

I have a main form which does processing for an extended period of time. Normally, progress bars are used to show either the loading status or simply show the program is still running/hasn't freezed. ...
3
votes
2answers
88 views

Thread-safe, in-memory LRU cache with a maximum item count of 10

I'm attempting to master LRU Caching. It must be thread safe, and it should preferably perform as well as web image-cache, (avg ~1MB). Please take a look to see if there's anything wrong, amiss, ...
-1
votes
1answer
51 views

Multithreading - program with lots of parallel routines (C++) [closed]

I'm coding a networking software, which has lots of functions (modules) which can be run in parallel. They share some resouces, like libnet_contexts of every type, ...
13
votes
2answers
195 views

Thread pool worker implementation

As an exercise in using C++11 features I decided to make a thread pool class. I would like to have a review on the code with focus on: Standards compliance / Portability issues / Best practices ...
7
votes
2answers
408 views

Generic cached value class mimicking Lazy<T>

Before I wrote this I searched and found a number of solutions that make use of a caching provider to handle a set of items. I felt that was too cumbersome of an approach and set out to create a class ...
10
votes
2answers
157 views

Sending SMS through twilio from play framework

I am trying to send SMS using Twilio with Scala 2.10 in Playframework 2.2, but this code is looking odd to me, maybe due to lots of conditions. I'm sure it needs some important reviews. ...
0
votes
0answers
89 views

Command line multipart file downloader using requests

The code below downloads file in multiple chunks if split is set to some number, however there is a limit to maximum possible splits defined below by maxSplits if ...
4
votes
1answer
34 views

Synchronized LinkedHashed map

I've written the following code ages ago (10+ years) which is part of a simple chat server. I'm going to refactor it a bit in java and then for fun I'm going to convert it to Scala and use Akka actors ...
2
votes
0answers
103 views

Netty-based safely network reconnection

I am writing a TCP client app using netty NettyConnectionManager.scala: ...
1
vote
1answer
56 views

Will this act like a ThreadPool? [closed]

I know that until the n threads will not complete their jobs, the new jobs will not be assigned, but will this code be thread-safe and execute ...
3
votes
2answers
100 views

Platform independant thread pool v2

This is a continuation of this question, v3 can be found here Taking into account the advise given by Loki, an implementation of the threadpool using a ...
8
votes
1answer
217 views

Platform independant thread pool

v2 of this question is here and v3 is here To get a better understanding of C++11/C++14, I thought I would develop a thread pool, even if it has been done to death! The only dependency outside of ...
10
votes
1answer
276 views

Thread-Safe Integer Sequence

I would like to give an Integer to whatever demands it. For that I use the following code ...
6
votes
2answers
235 views

Will this Circuit Breaker catch fire?

I was going to post this code as an answer to a recent question, but I wrote this code a little while ago (like, a year ago; if I recall correctly I wrote this after reading this article) and I'd like ...
10
votes
1answer
143 views

My first multi threading class

I've thrown everything I can at this, and I can't get it to lock or crash. My hope is that I have applied the principles correctly. I write client apps in JavaScript, and this is only the 3rd .NET ...
7
votes
2answers
164 views

How to make sure all the threads are getting consistent data without performance impacts?

I am working on a project in which I construct a url with a valid hostname (but not a blocked hostname) and then execute that URL using RestTemplate from my main ...
6
votes
1answer
410 views

Program to shutdown computer after a certain time

I'm trying to make a program that will shutdown my computer after a certain time that I will input via GUI. I'm wondering if I did it the correct way. Also, will this slow down my computer while it ...
6
votes
1answer
263 views

Is this Android click handler using threads correctly?

I am implementing a thread like the following. Is my implementation correct? It works well, but I need a check. ...
4
votes
1answer
1k views

Writing to file in a thread safe manner

I'm writing Stringbuilder to file asynchronously. This code takes control of a file, writes a stream to it and releases it. It deals with requests from asynchronous operations, which may come in at ...
6
votes
2answers
103 views

My EventBus system followup

This question is a followup from my previous question My EventBus system, and incorporates most points from @rolfl's answer. It includes, but is not limited to: Usage of ...
7
votes
1answer
89 views

My EventBus system

I decided to roll out my own EventBus system which is intended to be thread-safe. Hence a review should focus extra on thread safety apart from all regular concerns. The ...
12
votes
2answers
230 views

Can I make the thread safe case faster?

The code below is part of one of my projects called largetext, which actually stemmed from a question on StackOverflow. The goal is to provide access to a very large text file as a ...
2
votes
1answer
1k views

Generic, thread-safe MemoryCache manager for C#

Using this question as a base, and using some of the advice in the answers, I wanted to build out something that would be generic, thread-safe, and easy to use for at least one current and several ...
4
votes
1answer
95 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
113 views

CountdownLatch Thread-Safety Check

I've written this class as an exercise for a synchronization construct to be used across multiple threads. The intent is to have worker threads Increment() it, do ...
6
votes
1answer
117 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). ...
3
votes
1answer
161 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
74 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 ...
11
votes
2answers
197 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
257 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
117 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
82 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
639 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
132 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? ...
5
votes
2answers
4k 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
237 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
211 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
77 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
102 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
100 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
126 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? ...
10
votes
1answer
4k 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
3k 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
129 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
99 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 ...