thread-safety

NSInvocationOperation and main thread

Imagine that I have a view with some UIKit object as its subview (for example, UIActivityIndicatorView - this doesn't matter). This view also has a selector, called doSomething, which somehow manages UIKit object (in our example it can start or stop indicator view). I create NSInvocationOperation (from view's code parts) with initWithTa...

Safe to update separate regions of a BufferedImage in separate threads?

I have a collection of BufferedImage instances, one main image and some subimages created by calling getSubImage on the main image. The subimages do not overlap. I am also making modifications to the subimage and I want to split this into multiple threads, one per subimage. From my understanding of how BufferedImage, Raster and DataBu...

synchronizing reads to a java collection

so i want to have an arraylist that stores a series of stock quotes. but i keep track of bid price, ask price and last price for each. of course at any time, the bid ask or last of a given stock can change. i have one thread that updates the prices and one that reads them. i want to make sure that when reading no other thread is updat...

Efficient implementation of threads in the given scenario

I've got a winforms application that is set up in the following manner: 2 buttons, a textbox, an class object MX with a collection K as its member, function X and another function, Y. Function X parses a large database and enumerates some of its data in collection K. Button 1 calls function X. Function Y walks through the above collect...

Java: thread-safe RandomAccessFile

Hi, After some serious googleing I found out that the RandomAccessFile-class is not thread-safe. Now I could use one semaphore to lock all reads and writes but I don't think that performs very well. In theory it should be possible to do multiple reads and one write at a time. How can I do this in Java? Is it possible at all? Thanks! ...

In Java, is a Comparator used in Collections.sort() thread safe?

If I create a single instance of a Comparator, can that instance be used across multiple threads to sort collections using Collections.sort()? Or, do I need to create a new instance of the Comparator for each call to Collections.sort() to ensure thread safety? ...

Is locking on the requested object a bad idea?

Most advice on thread safety involves some variation of the following pattern: public class Thing { private readonly object padlock = new object(); private IDictionary stuff, andNonsense; public Thing() { this.stuff = new Dictionary(); this.andNonsense = new Dictionary(); } public IDictionary S...

Peterson algorithm in Java?

Is there example implementation of Peterson algorithm for mutual exclusion in Java? ...

Is it safe to draw three separate QImages in three separate QThreads?

I have a QMainWindow with three widgets inside that are promoted to a class containing a subclassed QThread. They each draw on a local QImage in their rexpective qthread which is sent with a signal once its drawn and then rendered by calling update (mandlebrot example) from the slot. Is this safe or dangerous? They do not share any data...

Noise with multi-threaded raytracer

This is my first multi-threaded implementation, so it's probably a beginners mistake. The threads handle the rendering of every second row of pixels (so all rendering is handled within each thread). The problem persists if the threads render the upper and lower parts of the screen respectively. Both threads read from the same variables,...

Is this ruby code thread safe?

Is this code threadsafe? It seems like it should be, because @myvar will never be assigned from multiple threads (assuming block completes in < 1s). But do I need to be worried about a situation where the second block is trying to read @myvar as it's being written? require 'rubygems' require 'eventmachine' @myvar = Time.now.to_i Eve...

Is the Microsoft Enterprise Library 5.0 Logging Application Block thread safe?

I have some code that will be logging using the Logging Application Block in Enterprise Library 5.0 from different threads. Is the LAB thread safe? Can I log like normal from different threads or will I need to synchronize the logging code so that is only used from one thread at a time? ...

Asynchronous thread-safe logging in C++

I'm looking for a way to do asynchronous and thread-safe logging in my C++ project, if possible to one file. I'm currently using cerr and clog for the task, but since they are synchronous, execution shortly pauses every time something is logged. It's a relatively graphics-heavy app, so this kind of thing is quite annoying. The new logge...

C# making dictionary access thread-safe?

Possible Duplicate: Whats the best way of implementing a thread-safe Dictionary in .NET? Possible Duplicate: Whats the best way of implementing a thread-safe Dictionary in .NET? Hi, whats is the easiest way to make C# dictionary access thread safe? Preferablly just using lock(object) but any other ideas welcome! ...

Variable lenght arguments in log4cxx LOG4CXX_ macros

I am using log4cxx in a big C++ project but I really don't like how log4cxx handles multiple variables when logging: LOG4CXX_DEBUG(logger, "test " << var1 << " and " << var3 " and .....) I prefer using printf like variable length arguments: LOG4CXX_DEBUG(logger, "test %d and %d", var1, var3) So I implemented this small wrapper on top...

Is there a straightforward way to have a thread-local instance variable?

With the ThreadStatic attribute I can have a static member of a class with one instance of the object per thread. This is really handy for achieving thread safety using types of objects that don't guarantee thread-safe instance methods (e.g., System.Random). It only works for static members, though. Is there any straightforward way to d...

Cache consistency & spawning a thread

Background I've been reading through various books and articles to learn about processor caches, cache consistency, and memory barriers in the context of concurrent execution. So far though, I have been unable to determine whether a common coding practice of mine is safe in the strictest sense. Assumptions The following pseudo-code i...

Read -> change -> save. Thread safe.

This code should automatically connect players when they enter a game. But the problem is when two users try to connect at the same time - in this case 2nd user can easily overwrite changes made by 1st user ('room_1' variable). How could I make it thread safe? def join(userId): users = memcache.get('room_1') users.append(user...

Application and service with one database

Hi. I have android application and service that runs in separate process. Application and service read and write to same database (and same table). What is the best way to work with database? How to prevent locks? ...

proper use of volatile keyword

I think i have a pretty good idea about the volatile keyword in java, but i'm thinking about re-factoring some code and i thought it would be a good idea to use it. i have a class that is basically working as a DB Cache. it holds a bunch of objects that it has read from a database, serves requests for those objects, and then occasional...