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
35 views

C++ singleton — not full C++ 11 standard [closed]

I'm struggling to design a thread-safe singleton implementation in C++, but it will be targeted primarily on the Visual Studio 2012 environment. I know that the C++ 11 standard guarantees that this ...
6
votes
1answer
61 views

A thread-safe stop watch utility class

I am writing a stop watch utility class in Java that I want to be thread-safe (concurrent). Here is what I have right now: ...
7
votes
0answers
123 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
2
votes
1answer
35 views

Safe Thread Synchronization

I think the following is thread safe. Am I right? How would you improve this code? Are there new APIs or methods I can use? Data: ...
3
votes
0answers
75 views

Timeout watchdog using a standby thread

The simple but generic timeout class to be used watching for network connections, user input, filesystem events, and is intended to have a very simple interface specific to only our use cases (i.e. no ...
2
votes
1answer
83 views

Simple thread-safe loading cache based on RxJava

I'm sketching a simple thread-safe cache which can load missing values. It is based on RxJava's Observable which also means that it should be possible for a client to join a request for value which is ...
4
votes
3answers
80 views

Thread safe cache for write through and writeback

This cache is like a list where new elements are inserted in the middle, cache hits are put to head of the list and replaced elements are taken from the end. Would I just use a list the lookup would ...
5
votes
2answers
156 views

Synchronization in an event manager

I'm working on an event manager, and I am wanting it to be a tool developers use. It is lightweight and it uses annotations to register events. I've tried to set up ...
1
vote
1answer
92 views

Thread Safe Objects in CSharp - ConcurrentDictionary

I'm using ConcurrentDictionary to hold the records.. I'm reading files from the local system in parallel, to speed up the process. Sample 1: ...
3
votes
1answer
84 views

Concurrent LRU cache using sychronizedMap() or ReadWriteLock

Trying to implement a simple, thread-safe LRU cache that's meant for "read mostly" use. Collections.sychronizedMap() Clean, simple, not much else to say. ...
2
votes
3answers
62 views

Thread safety and performance when multiple threads write into same Writer

Multiple threads write data to a file. When maxLines is reached, the file is closed and a new file is created: ...
6
votes
1answer
90 views

Fast Thread- and multiprocess-safe file operations in python under Linux

I'm trying to implement an alternative to python built-in open(), but safe for use in multi-threaded and multiprocessing environment. I'm using advisory locking, ...
3
votes
2answers
143 views

Simple C++ thread pool

I wrote a minimalistic thread pool using some C++11 features. I've used it on two projects so far and it has worked fine, but when I ran the code on my laptop, I believe that my thread pool might be ...
3
votes
1answer
87 views

Simple concurrent freelist

To become better acquainted with the Intel Parallel Studio XE profilers I'm currently messing around with a simple concurrent freelist. I'm fairly certain that it's thread-safe. It uses Acq/Rel ...
3
votes
2answers
99 views

Is this a thread-safe implementation of background bitmap generation?

For a game implementation, I have a very large overview map with multiple layers (namely base-map / units / highlight & info / fov-shading) of which the first is CPU-intensive to generate. I have ...
2
votes
1answer
72 views

A thread-safe initialization guard

I have written a type with the following public API: ...
4
votes
1answer
63 views

C++11 lock free collection similar to std::forward_list - follow-up

Thread safe and lock free collections are very hard to write, so I'd appreciate any feedback, especially regarding bugs. The code below is a self contained cpp including some tests. This question is ...
4
votes
1answer
80 views

C++11 lock free collection similar to std::forward_list [closed]

I'm new to explicit memory ordering, and any kind of thread safety is hard to implement right to begin with. Please let me know if you see any problems, or have suggestions for improvement. Written in ...
1
vote
2answers
137 views

Updating list of string while others reading it in Java

I have a logging solution that writes down the hashes of messages. I consider some of these hashes to be safe and I want to skip logging those. I have implemented a whitelist that is a directory ...
1
vote
1answer
88 views
7
votes
3answers
1k views

Dining philosophers problem in C++11

Is this implementation correct? Do you find any threading problem? Also, what parts of the code can be changed to be more C++11-ish? ...
7
votes
1answer
196 views

Lock Using “Interlocked” vs lock Statement (“Monitor”) (Followup)

This is a followup to a previous question. Considering: Interlocked.CompareExchange generates a memory barrier, Intended to be used with very fast operations ...
4
votes
2answers
165 views

Lock Using “Interlocked” vs lock Statement (“Monitor”)

A followup question can be found here, based on this question and it's answer. Considering: Interlocked.CompareExchange generates a memory barrier, Intended to ...
4
votes
2answers
817 views

Running Code Just Once

I want a code run just once (say in Dispose). WriteOnceBlock<T> from TPL Data Flow could be used here; but again if we ...
3
votes
1answer
110 views

Ensure only a single instance of static template class member

I am interacting with a C library, whose documentation states that certain functions are not thread safe. Since its functions deal heterogeneously with multiple types, I have written a template ...
4
votes
1answer
155 views

Increasing performance and accuracy in multithreaded loop

I was wondering if the following set up will return consistent result, i.e. no thread function call will be skipped. Also, is there any way to improve the threaded loop? Note the first loop is the ...
3
votes
2answers
92 views

Typetokens in C++11

I have written a typetoken library in C++11 and I want to know if it is indeed typesafe, threadsafe and complete. The purpose of this library is to give an unique ID to every requested typename ...
6
votes
1answer
506 views

Efficiently using ZeroMQ sockets in Java

I am working on multithreading project and I am using ZeroMQ socket to send the data as a byte array. Below is my example which works fine. I'm opting for code review to see whether it can be improved ...
5
votes
2answers
419 views

Could I dispose IDisposable objects that are part of a Thread?

I have a question about using an IDisposable object in the ThreadStart function. I have a class that derives from ...
4
votes
2answers
299 views

Concurrent activity on ArrayList

I have an immutable Point class and a CollectionPoint class which manages instances of my ...
4
votes
1answer
254 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
338 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
321 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
269 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
256 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
475 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
89 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, ...
14
votes
2answers
806 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
448 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
254 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
192 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
42 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
295 views

Netty-based safely network reconnection

I am writing a TCP client app using netty NettyConnectionManager.scala: ...
1
vote
1answer
62 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
276 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
727 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
1k 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
534 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 ...
11
votes
1answer
207 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
303 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 ...