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

0
votes
0answers
29 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
28 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
40 views

Safely network reconnection (netty based)

NettyConnectionManager.scala: ...
1
vote
1answer
51 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
66 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
93 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 ...
9
votes
1answer
178 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
157 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 ...
9
votes
1answer
128 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
116 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
157 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
193 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
228 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
94 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
76 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
208 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 ...
0
votes
0answers
37 views

Lock-Free interface to the user?

I'm working on a profiling library for C++. It is available here: CxxProf Github Project The interface to the user is a simple wrapper. Here's a part of CxxProfileStatic.cpp: ...
1
vote
1answer
271 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
83 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
72 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 ...
6
votes
1answer
86 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
98 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
62 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
164 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
124 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
111 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
71 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
300 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
131 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
2k 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
170 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
136 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
71 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
93 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
70 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
117 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? ...
11
votes
1answer
2k 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
1k 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
113 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
93 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
275 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
195 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
2answers
310 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
141 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
1k 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
44 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
351 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
813 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 ...
5
votes
1answer
295 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
239 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 ...