thread-safety

Threadsafe lazy loading when the loading could fail

Hello, I've been spending about an hour searching for a concensus on something I'm trying to accomplish, but have yet to find anything conclusive in a particular direction. My situation is as follows: I have a multi-threaded application (.NET web service) I have classes that use objects that take non-negligible time to load, so I wou...

Why can't terminate a process if its threads are in unkown states?

From my experience, when main thread is ready to exit, it should wait until other threads normally exit. But from this link http://msdn.microsoft.com/en-us/library/ms686722(v=VS.85).aspx, it looks when process is terminated, all related resources are freed, so if certain worker thread is doing heavy work, waiting may be a litter longer....

Using Array with multiple reader threads + writer

Hi I am no sure about this .. Using an int[] array. If in my application, a thread A reads while a thread B writes into the same array element, will everything hold ? I'd rather not have a synchronized block on reading also - this is used in a web service, so I won't be able to service multiple clients in parallel. Thanks. Olivier ...

python: elegant way to deal with lock on a variable?

I have code that looks like something like this: def startSearching(self): self.searchingLock.acquire() searching = self.searching if self.searching: self.searchingLock.release() self.logger.error("Already searching!") return False self.searching = True self.searchingLock.release() #some...

Rhinomocks with .net 4 threading

So I have a little app which will process a load of files and I'm trying to write tests for the class which will handle looping through the files and firing them to various places. This was an obvious place to try out the new parallel library stuff. Heres a simplified version of the code I'm testing: public void ProcessSomeFiles(IEnumer...

Strange behavior with a low thread priority.

I have 2 threads, one that decodes bitmaps from the assetManager, and another that is my SurfaceView. When i set the priority of the bitmap decoder very low, i actually get more lag then if its much higher. Why would it act like that? thanks. Heres my code: public void bitmapLoader(final String filePath,final int pathVariable) ...

Does using a lock has better performance than using a local (single application) semaphore ?

Does using a lock has better performance than using a local (single application) semaphore? I read this blog from msdn : Producer consumer solution on msdn and i didn't like their solution to the problem because there are always 20 elements left in the queue. So instead, i thought about using a Semaphore that will be available only in...

How to guarantee thread-safety for overridden methods?

I've been struggling with this for 7 days now. Your insights will be greatly appreciated. Consider the framework code. final class Main { // assuming programmerCode was injected Interface inter = (Interface) programmerCode; inter.doProcess(); } interface Interface { void doProcess(); } abstract ProgramApp implements Interface { ...

Why do I need a memorybarrier

C# 4 in a Nutshell (highly recommended btw) uses the following code to demonstrate the concept of MemoryBarrier (assuming A and B were run on different threads): class Foo{ int _answer; bool complete; void A(){ _answer = 123; Thread.MemoryBarrier(); // Barrier 1 _complete = true; Thread.MemoryBarrier(); // Barrier ...

Thread Safe Publish Subscribe in .Net

I created a simple set of interfaces and a class that allow me to publish the additions and removals of items in a generic dictionary. Subscribers receive the entire list when they subscribe and after that, they get only the changes. Although my solutions work, I am looking for something a little more standard, a little less home-grown....

Silverlight : Create Generic Control from backgroundWorkder Thread

Hi, I'm in trouble when using the background worker to create my object model. As I understand why, I'm unable to find a workaround. Here is the pseudo logic : Call Webservice async When received, open a background worker, and load data into controls in the background in the Load method, search for an existing object and if not foun...

Cannot unlock Mutex

Note: I am using the open source Poco C++ libraries I have a parent thread that creates many child threads to deal with incoming connections, each of these child threads maintains an XML document, which the parent thread can request at anytime via callback. Therefore I have a mutex protecting this document. My problem arises in tha...

Is getting and setting a simple static properties thread safe?

Possible Duplicate: Are C# auto-implemented static properties thread-safe? In the following example class static class Shared { public static string[] Values { get; set; } } many reader threads read the Values string array periodically, while from time to time a single writer will replace the whole array with a new valu...

Can I ignore thread safety when programming in Erlang?

I've just started learning about thread safety. This is making me code a lot more defensively, perhaps too defensively. Would using a functional language like Erlang completely rid me of this concern? ...

There is a rule to find out which objects could possibly have concurrent access in a Java program?

There is a rule to find out, for sure, all objects that could possibly have concurrent access in a Java program? My intention is use such rule, if it exists, to find out which Java classes could possibly have concurrent access and then guarantee that they are thread-safe. This rule could be very useful when inspecting a large Java projec...

Synchronizing Event Calls from Threads to Event Handlers on Windows Forms

I have an object that is updated from a polling loop on a thread. This object fires particular events when data changes, etc. I'm trying to use this object in conjunction with a windows form, where I create event handlers on the form to update the UI. Of course, this causes cross-thread operation exceptions if I try to manipulate the ...

Should we use EventQueue.invokeLater for any GUI update in java desktop application?

I know that by using this method, the runnable parameter is submitted to the system EventQueue. But should all GUI updates be done this using this method? I mean, if i want to say, change a text of JButton, should i use something like this: java.awt.EventQueue.invokeLater(new Runnable() { public void run() { jButton1.setT...

Static method from servlet

Hello, I'm writing my Servlet application and would like to use the following static method which will multiply x and y. public class Helper { private Helper() { throw new AssertError(); } public static int mutltiply(int a, int b) { int c = a*b; return c; } } I understand that Servlets are mu...

.NET thread safety

List.Add is an instance method. That means it's not guaranteed to be thread-safe. What does this mean? Possibility 1. That if two threads invoke .Add on different instances, there could be an unexpected result depending on the phase of the moon? Possibility 2. That if two threads invoke .Add on the same instance, there could be an unex...

Trade off between a recursive mutexes V a more complex class?

I've heard that recursive mutexs are evil but I can't think of the best way to make this class work without one. class Object { public: bool check_stuff() { lock l(m); return /* some calculation */; } void do_something() { lock l(m); if (check_stuff()) { /* ... */ } ...