Questions tagged [thread-safety]

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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
105 views

Sending messages for processing

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 a ...
Decrypter's user avatar
  • 377
5 votes
1 answer
468 views

Review of simple Java Actor library

How can I improve this code? Also available from git://github.com/edescourtis/actor.git . Actor.java ...
Eric des Courtis's user avatar
2 votes
0 answers
102 views

D3D COM Object Pooling

I'm using the following pattern to pool D3D objects globally in my application. Is it a good idea (alternatives)? Is it thread-safe? ...
ronag's user avatar
  • 576
3 votes
1 answer
2k views

Atomically incrementing a value in a map in Clojure

I am working out a bit of Clojure code that will take a ref to a map and increment a key value pair in the map. I think I am using ref correctly, but Im not sure about atom. Do I need to use swap! ...
David Williams's user avatar
3 votes
2 answers
301 views

Using volatile instead of synchronized for a simulation

I want to know if using volatile in this scenario will give better performance than using synchronized, specifically for the ...
vjames's user avatar
  • 33
16 votes
1 answer
6k 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 ...
Javier Blazquez's user avatar
1 vote
1 answer
111 views

Timing/Synchronization issues with interrupt-reliant code

I've started to program a state machine on a PIC18F2550 microcontroller. In each state of my machine, there is a designated block of code that runs for a specific amount of real time, such as 20 or 30 ...
BB ON's user avatar
  • 113
4 votes
1 answer
2k 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 ...
Michoel's user avatar
  • 93
2 votes
1 answer
1k views

Producer/Consumer with some limitations

The code realizes producer/consumer problem with multiple producers and consumers. Have this code any potential deadlock or races? ...
Hamlet Hakobyan's user avatar
2 votes
4 answers
12k 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 ...
xkcd's user avatar
  • 123
3 votes
1 answer
3k 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 JDBC-...
user21973's user avatar
  • 181
4 votes
3 answers
4k 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 ...
charliehorse55's user avatar
4 votes
3 answers
325 views

Is this Agent/Actor implementation issue free?

I implemented this Agent class for a project recently and was wondering if I could get some other eyes to look at it -- I'm currently the only developer where I work so I can't exactly ask someone ...
paul's user avatar
  • 168
3 votes
2 answers
5k 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 ...
almathie's user avatar
  • 133
4 votes
1 answer
1k views

BlockingQueue Implemetation using ReentrantLock

I was writing my own implementation of BlockingQueue for practice. I am trying to avoid using the synchronized keyword for the methods. I would instead like to use ReentrantLock. What is the best way ...
Hir's user avatar
  • 91
2 votes
2 answers
3k views

Lock-Free Ring Implementation

I am wondering if someone can take a look at my lock-free, circular ring implementation which I use to implement a background logger. The CircularRing pre-...
CaptainHastings's user avatar
2 votes
1 answer
3k 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 ...
nohros's user avatar
  • 121
4 votes
6 answers
9k 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 safe/...
Tom's user avatar
  • 141
4 votes
1 answer
1k views

Custom dictionary for caching assistance

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 ...
Earlz's user avatar
  • 227
3 votes
2 answers
416 views

Invoking a callback on a pool of threads

This class acts like a synchronization context except the work could be done on any one of the available threads. I've done quite a bit testing on my own, but I'm generally concerned about potential ...
dodald's user avatar
  • 133
7 votes
2 answers
487 views

Synced/Atomic access

Forward I would love any comments you have, any ideas, any flaws you can find, and any suggestions you might have regarding the code below. If this is similar to other implementations, I would love ...
Lockszmith's user avatar
5 votes
2 answers
456 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 ...
John Fitzpatrick's user avatar
1 vote
2 answers
906 views

Querying a list of jobs on a server using EJBs

Inspired by this question, I have a Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application. For this I have a bean that maintains a ...
Martin Schröder's user avatar
7 votes
4 answers
464 views

Handling messages from a server

I've never really done anything with concurrency, so I'm not sure if this is done correctly. Basically, I have a class that handles all messages from the server and decides what to do them. It uses ...
Austin's user avatar
  • 211
12 votes
2 answers
35k views

Add/Remove items thread-safely in List<T>

Recently I had to lock collections (of type List<T>) when items were added or removed. Because several collections were used in given code instead of creating ...
Leri's user avatar
  • 287
2 votes
1 answer
5k views

Boost Threads - Producer Consumer threads with synchronization

Please review this for concurrency correctness: ...
Eternal Learner's user avatar
5 votes
1 answer
237 views

Is this a thread safe way to control access to a reusable resource? Is there a better way?

...
John Gietzen's user avatar
3 votes
4 answers
4k views

Java Non Reentrant Lock Implementation

I have implemented a Non Reentrant Lock. I want to know if this has any mistakes, race conditions etc. I am aware of the fact that existing libraries have to be used (instead of writing our own), but ...
vikky.rk's user avatar
  • 133
5 votes
2 answers
655 views

Library for doing A/B tests in a web app

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 ...
tucaz's user avatar
  • 335
15 votes
2 answers
1k views

Concurrency limit map in Go

Task: per host concurrency limits for web crawler (map[string]Semaphore). I considered chan struct{} (chan bool) approach, but ...
temoto's user avatar
  • 251
3 votes
1 answer
606 views

C# Array Mutator Methods to mimic JavaScript Array Mutator Methods

Between .NET's built-in collection libraries and LINQ extension methods, I never have to use arrays. An unfortunate consequence of this is that I am probably less competent in working with this very ...
smartcaveman's user avatar
3 votes
1 answer
2k 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 ...
Richard Friend's user avatar
12 votes
1 answer
18k views

Thread-safe lock-free counter

I was using such code: ...
Oleg Vazhnev's user avatar
3 votes
1 answer
2k views

Mutex implementation for a uniprocessor bare metal embedded OS

I wrote this recently for one of my projects. Are there any error you can spot or a feature which could be implemented without eating up resources or some optimisations? Also, this isn't meant for ...
3 votes
5 answers
453 views

Configurable synchronization approach in Java

I am interested in the community opinion about the following approach for the synchronization. Generally it is based on the idea to have a configurable way to apply locking on some logic parts. Any ...
ykhrustalev's user avatar
5 votes
2 answers
1k views

Maintaining a count with two threads using conditional variables

This is just a program to show the use of conditional variables when two threads are involved. One thread wants a non-zero value of count, and other thread is ...
Aquarius_Girl's user avatar
11 votes
1 answer
7k views

Timer to poll a Delegate

This is a followup to this where I was initially using a single thread and Thread.Sleep() to poll a delegate. I was recommended to use a timer and the ...
Alain's user avatar
  • 472
2 votes
1 answer
526 views

Webservice methods using EclipseLink and database entities

I am wondering if this is a good and correct way to write the implementation of two web service methods (get/set methods). The setPerson method can be called from ...
Rox's user avatar
  • 121
1 vote
1 answer
159 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 ...
jiduvah's user avatar
  • 433
3 votes
1 answer
2k 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 ...
Padarox's user avatar
  • 31
3 votes
1 answer
22k views

Simple generic multithreaded queue

This is a simple thread safe queue that is used in a producer-consumer model. ...
Odys's user avatar
  • 133
4 votes
1 answer
757 views

Alter centralized logging code to be thread safe

I am using this code for receiving log messages from my clients. I receive more than 1000 connections per minute and I want to increase my log handling, which I have done with java threading. What ...
kannanrbk's user avatar
  • 175
5 votes
4 answers
17k views

Thread-safe object cache, for read, high performance in .NET

I want to realize an object cache which holds objects loaded from database, file or other slow access source, to make them available quickly with high performance. There will be a lot of accesses to ...
Erik Hart's user avatar
  • 301
4 votes
1 answer
3k views

Thread safe cache implementation

Please review this implementation of thread-safe chache. ...
Vlad Minaev's user avatar
5 votes
1 answer
15k views

Generic wrapper for System.Runtime.Caching.MemoryCache

I have implemented a simple generic wrapper for MemoryCache class. Its interface looks like ConcurrentDictionary class but I tried to keep it simple. I tried to keep operations atomic, hoping not to ...
Ufuk Hacıoğulları's user avatar
1 vote
2 answers
492 views

Is this method thread safe?

Are these methods getNewId() & fetchIdsInReserve() thread safe ? ...
Rajat Gupta's user avatar
4 votes
2 answers
9k views

Multithreaded item-processing queue

I have this Queue declared in my class: static private Queue<SignerDocument> QUEUE = new Queue<SignerDocument>(); ...
Guilherme de Jesus Santos's user avatar
3 votes
2 answers
1k views

Thread design for sending data to multiple servers

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, ...
Aquarius_Girl's user avatar
7 votes
1 answer
2k 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 ...
Lightness Races in Orbit's user avatar

1
7 8 9
10
11