2
votes
1answer
50 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 ...
1
vote
2answers
77 views

Correct way to delete elements from a ConcurrentDictionary with a predicate

I have written a caching wrapper class for ConcurrentDictionary. Basically it has a timer that checks if items are expired and removes them. Since ConcurrentDictionary does not have RemoveAll method ...
2
votes
1answer
40 views

Synchronization of remote files download

Preamble: it's a self-assigned and pure syntetic task to learn (and remember what I already knew) C# threads and synchronization and data structures. The original question was here ...
3
votes
1answer
118 views

Dining Philosophers problem Solution with Java Reentrant Lock

I have implemented Dining Philosopher problem using ReentrantLock in java. The goal of this program is Every philosopher should follow the workflow of think,getchopsticks,eat,putchopsticks (No ...
1
vote
1answer
35 views

Ensuring my program is thread safe

I have a class which is responsible for waiting until a message is added to a message list and then sending it off to get processed withdrawMessages - waits for message. I wait a total of 2 minutes ...
3
votes
1answer
127 views

Review of simple Java Actor library

How can I improve this code? Also available from git://github.com/edescourtis/actor.git . Actor.java package com.benbria.actor; public interface Actor<T> extends Runnable { public ...
3
votes
2answers
63 views

Is this a scenario to use volatile instead of synchronized?

I want to know if using volatile in this scenario will give a better performance than using synchronization. Specifically for the paused and running instance variable in the SimulationManager class. ...
2
votes
0answers
348 views

Lock-free multiple-consumer multiple-producer queue

The code below implements an intrusive lock-free queue that supports multiple concurrent producers and consumers. Some features: Producers and consumers work on separate ends of the queue most of ...
3
votes
1answer
214 views

Java thread safety and caching techniques

This is my first Java multi-threading code. It is part of an Android application that is a client to a webpage that serves books. Each page of the book is in a separate PDF, and the Book class ...
2
votes
4answers
182 views

Designing a better logger class

Could you please critisize the logger class below? Can it be used in a multi threaded web environment? If not how can I improve it? Is there anything wrong with locking in WriteToLog method or ...
3
votes
1answer
118 views

Thread Safety issues in the multithreading code

I am working on a project in which I have two tables in a different database with different schemas. So that means I have two different connection parameters for those two tables to connect using ...
2
votes
1answer
179 views

Lock free MPMC Ring buffer implementation in C

I have written a lock free MPMC FIFO in C based on a ring buffer. It uses gcc's atomic built-ins to achieve thread safety. The queue is designed to return -1 if it's full on enqueue or empty on ...
2
votes
2answers
120 views

Simple FIFO Job list in Java

For the first time I have to play with Threads in java. Basically, my code is a simple FIFO job queue. The main thread regularly puts jobs in the queue wich need to be executed. The code below is a ...
2
votes
1answer
189 views

Publisher/Consumer thread-safe lock-free queue with a single publisher/consumer

The code above is a implementation of a lock-free queue that makes the assumption that there is exactly one Consumer thread and one Producer thread. This works as intended? The memory barriers is used ...
4
votes
6answers
454 views

Strategy for avoiding threadpool starvation while performing cpu bound jobs in a queued fashion

My aim is to avoid using threadpool threads for CPU bound work, thus avoiding a situation where IIS stops responding to new requests. Can you see any problems with the code below? Is this a ...
4
votes
1answer
199 views

Is this custom dictionary thread-safe?

I'm writing a custom dictionary which is to be used as a helper for caching. The reason I use delegates is because it must interface with generated code, so I can't change this. However, you can ...
4
votes
2answers
185 views

Multithreading correctly done?

I rarely write multithreaded code, and am on shaky ground when doing so. I make mistakes. I would like a sanity check of something I am going to introduce in one of my apps. There will be exactly ...
5
votes
2answers
239 views

How can I make this fast and more readable?

I made a simple library to help me doing A/B tests in a web app. The idea is simple: I have two or more page options (url) for a given page and every call to the library method should give me a url so ...
3
votes
1answer
346 views

.Net caching service - thread safety

I have a simple cache service that i am using inside my WPF prism application, i am concerned about the thread safety of it - we will be accessing this via multiple threads and using the current code ...
2
votes
0answers
553 views

The correct (and safe) way to use a Timer to poll a Delegate

This is a followup to Polling loop to run in a background thread where I was initially using a single thread and Thread.Sleep() to poll a delegate. I was recommended to use a timer and the ThreadPool ...
0
votes
1answer
81 views

Thread Safe Server Querier

I wanted to make a class that connects to my server and returns a value, a url in this case. As Android 4.0 doesn't let me run network task on the main UI thread(rightly so) I have made this. Please ...
1
vote
1answer
291 views

Loading an Object from File with Type-Safety and Thread-Safe access

I'm attempting to write a bit of code that allows for easy and safe access to objects in a file. It seems to work great but I was curious if there was an easier way to do this or if Java already has ...
1
vote
1answer
1k views

Simple generic multithreaded queue

This is a simple thread safe queue that is used in a producer-consumer model. public class ThreadedQueue<TType> { private Queue<TType> _queue; private object _queueLock; ...
4
votes
1answer
309 views

is this thread safe?

I am using this code for receiving log messages from my clients I receive more than 1000 connections per minute. I want to increase my log handling. I did with java threading. I have a doubt if it ...
2
votes
2answers
229 views

Is this method thread safe?

Are these methods getNewId() & fetchIdsInReserve() thread safe ? public final class IdManager { private static final int NO_OF_USERIDS_TO_KEEP_IN_RESERVE = 200; private static final ...
4
votes
2answers
2k views

Did I need to use lock to ensure that Queue.Dequeue is Thread Safe in this case on .NET 2.0?

Is this ok? I am using C# and .NET 2.0 I have this Queue declared in my class : static private Queue<SignerDocument> QUEUE = new Queue<SignerDocument>(); I fill this Queue with some ...
2
votes
2answers
396 views

Thread design for sending data to multiple servers?

Language: C++ Thread library: PThreads In the following code, checkServerExists function checks if the server exists in the vector. If it does, then the new message is directly pushed in the vector, ...
0
votes
0answers
537 views

Have I thought of everything in this wrapper around boost::thread_group?

boost::thread_group doesn't automatically clean up contained threads when they end, so I needed something like that described in this boost-users list post. However, in my opinion that code is not ...
4
votes
1answer
280 views

Activeresource-response gem

I created my first gem for Rails today. https://github.com/Fivell/activeresource-response. This gem adds possibility to access http response object from result of activeresource call. I don't know ...
4
votes
2answers
939 views

thread-safe stl map accessor

So after learning that stl map containers are not inherently atomic and therefore not thread-safe (check out this related stackoverflow question and usage example), I decided to create code that would ...
4
votes
1answer
1k views

Singleton class extending a parent class to utilise shared functionality

I have a singleton class which extends from an abstract java class. Two singleton classes extend from ItemImageThreadManager, the reason for this is to use shared scheduling functionality. A thread is ...
1
vote
1answer
226 views

Is this a safe/correct way to make a python LogHandler asynchronous?

I'm using some slow-ish emit() methods in Python (2.7) logging (email, http POST, etc.) and having them done synchronously in the calling thread is delaying web requests. I put together this function ...
3
votes
3answers
577 views

Is this code OK, to thread safety and delegates?

I've created some code, in main class loop are generated numbers (0~100), and when is generated number > 20 its value is passed to the thread where is simulated some work with this number. Meanwhile ...
2
votes
1answer
240 views

What do you think about resource locker in Qt?

The idea is to lock resource, in c# or java way un Qt with code lock(obj){/*process with locked obj*/} No I see, the problem with deleting obj under lock. resourcelocker.h #ifndef RESOURCELOCKER_H ...
3
votes
1answer
295 views

Single word CAS tagged pointer for algorithms susceptible to the ABA problem

I've been looking for a solution to the ABA problem for a lock-free stack. Searching the Web revealed patented and complicated hazard pointers and tagged pointers using double compare-and-swap (DCAS, ...
2
votes
1answer
1k views

A simple thread-safe queue in python

I'm trying to implement a kind of message queue. Tasks will come in at unknown random times, and must be executed FIFO. I can do multiple tasks in one hit, but the setup and tear down unavoidably ...
1
vote
1answer
1k views

Simple multi-threaded Java server loop

I'm new to sockets and servers in general and I would like to know if I'm doing something really wrong in the following server loop for spawning threads to process requests. private static ...
4
votes
1answer
290 views

Can you spot a threading bug in this implementation of costreams?

I am not very good with thread-safety and often fall prey to subtle issues in concurrency. Therefore, I hope that someone here might be able to tell me whether there is a subtle concurrency issue ...
23
votes
5answers
3k views

Is this (Lock-Free) Queue Implementation Thread-Safe?

I was trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently. Would you ...