thread-safety

Are C# structs thread safe?

Is a C# struct thread-safe? For example if there is a: struct Data { int _number; public int Number { get { return _number; } set { _number = value; } } public Data(int number) { _number = number; } } in another type: class DadData { public Data TheData { get; set; } } is property named TheData, thread-safe? ...

Are Remoting client-side object thread-safe ?

Can synchronous members of remoting proxy object be called from multiple threads simlutaneusly ? Auto generated proxy, in my case it is .NET1.1 remoting. The server model is SingleCall (but I guess that this is not importantn for client model). Or it is necessary to synchornize access to the proxied object ? I have only ane channel and ...

thread-safety question

A simple situation here, If I got three threads, and one for window application, and I want them to quit when the window application is closed, so is it thread-safe if I use one global variable, so that three threads will quit if only the global variable is true, otherwise continue its work? Does the volatile help in this situation? C++...

C# DataSource Class and Thread Safety

What would be a good way to writein C# a .NET3.5 Thread Safe DataSource Class. The class would connect to SQL Server and every method would execute a Stored Procedure. When the code worked single threaded. I had a Singleton DataSource Class with a private SqlConnection member. Each method opened and closed that connection. When running...

Is Joiner thread safe?

Is google collections Joiner thread safe? ...

What thread are iphone delegate methods run in for webview and core location callbacks?

I have an issue that looks like a race condition with a webview callback and a location manager callback that interact with the same variables and an alert dialog - the dialog is created in the location callback and should be dismissed in the webview callback. I thought that the delegate callbacks for standard objects like the webview a...

How to do compare and increment atomically in C/C++

In my attempt to develope a thread-safe c++ weak pointer template class, I need to check a flag that indicating the object is still alive, if yes then increment the object's reference count and I need to do the both steps atomically. I know the existance of intrinsics functions provided by the compiler for instance _InterlockedCompareExc...

Are indivisible operations still indivisible on multiprocessor and multicore systems?

As per the title, plus what are the limitations and gotchas. For example, on x86 processors, alignment for most data types is optional - an optimisation rather than a requirement. That means that a pointer may be stored at an unaligned address, which in turn means that pointer might be split over a cache page boundary. Obviously this c...

Resolving concurrency problem around collections

Hi, I'm having issues with concurrent usage of a shared collection with a multi-player synchronous game I'm working on. I did some digging around and found a neat thread-safe IEnumerator/IList implementation on Alexey Drobyshevsky's post on codeproject here: http://www.codeproject.com/KB/cs/safe_enumerable.aspx After adopting his impl...

What is a good way to test that a Java method is synchronized?

I have several classes that implement some interface. The interface has a contract, that some methods should be synchronized, and some should not, and I want to verify that contract through unit tests for all the implementations. The methods should use the synchronized keyword or be locked on this - very similar to the synchronizedColl...

Static method to be accessed by multiple threads, Java

Hi, I am using a third party library to do hand evaluation of 7 card poker hands. The method evaluate in this library is declared as public static and I believe it alters some global static arrays within the class. The problem I have is that as I am doing an enumeration algorithm of about 10m enumerations I want to parallelize it, there...

Is it okay to pass injected EntityManagers to EJB bean's helper classes and use it?

We have some JavaEE5 stateless EJB bean that passes the injected EntityManager to its helpers. Is this safe? It has worked well until now, but I found out some Oracle document that states its implementation of EntityManager is thread-safe. Now I wonder whether the reason we did not have issues until now, was only because the implement...

Proving the following code not thread safe

Hi, How can I quickly prove that the following class is not thread-safe (as it uses Lazy Initialization and not using synchronization) by writing some code ? In other words, if I am testing the following class for thread safety, how can I fail it? public class LazyInitRace { private ExpensiveObject instance = null; public Expensi...

Cleaning up threads referencing an object when deleting the object (in C++)

I have an object (Client * client) which starts multiple threads to handle various tasks (such as processing incoming data). The threads are started like this: // Start the thread that will process incoming messages and stuff them into the appropriate queues. mReceiveMessageThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)receive...

Is this technique of ASP.NET session access multi-user-safe?

I am looking at a design pattern which has come up in quite a few of my firm's projects. It has historically functioned correctly, however I have heard some other developers argue that there is a possibility of session corruption using this pattern. I'm looking for insight from other .NET developers here on Stack Overflow. Basically, t...

Lock Acquisition Order

Hi, With the following code, if a thread calls LoggingWidget.doSomething(), what is the order of lock acquisition that the thread has to go through? (i.e. does it get the Lock on LoggingWidget first, and then gets the lock on Widget ? ) public class Widget { public synchronized void doSomething() { } } public class LoggingWidg...

Why is synchronization needed here?

Hi, I am trying to plug some shameful gaps in my Java threading knowledge, and I'm reading Java Concurrency in Practice by Brian Goetz et al (highly recommended BTW), and one of the early examples in the book leaves me with a question. In the following code, I totally understand why synchronization is needed when updating the hits and ...

Thread Safety framework

Hi, The following class is not thread-safe (as proven in http://stackoverflow.com/questions/2410499/proving-the-following-code-not-thread-safe ) Is there a framework out there that can help with either compile time / run time analysis and tell us that the following is not thread safe? For compile time, ideally in Eclipse the wiggly un...

Windows Form hangs when running threads

JI have written a .NET C# Windows Form app in Visual Studio 2008 that uses a Semaphore to run multiple jobs as threads when the Start button is pressed. It’s experiencing an issue where the Form goes into a comma after being run for 40 minutes or more. The log files indicate that the current jobs complete, it picks a new job from the li...

any primitive data type in c# is automic(thread safe)?

For example, do i need to lock 'bool' value when doing multithreading? ...