thread-safety

Ruby thread-safe class variables

I have a number of models that load a collection of strings, based on the user's i18n locale. In order to simplify things, each model that does so includes the following module: module HasStrings def self.included(klass) klass.extend ClassMethods end module ClassMethods def strings @strings ||= reload_strings! e...

What is a best approach to make a function or set of statements thread safe in C#?

What is a best approach to make a function or set of statements thread safe in C#? ...

Java: testing thread access to "not thread-safe" methods.

My strategy for threading issues in a Swing Java app is to divide methods in three types: methods that should be accessed by the GUI thread. These methods should never block and may call swing methods. Not thread-safe. methods that should be accessed by non-GUI threads. Basically this goes for all (potentially) blocking operations suc...

Are Python extensions produced by Cython/Pyrex threadsafe?

If not, is there a way I can guarantee thread safety by programming a certain way? To clarify, when talking about "threadsafe,' I mean Python threads, not OS-level threads. ...

Accessing the JDBC ResultSet concurrently in Spring

I am processing a large amount of data in a Spring JDBC DAO. The DAO directly returns an Iterator over the objects which operates on a bounded BlockingQueue using take() while the retrieval operation is happening in a separate thread (using an ExecutorService). Inside this thread I see the following behaviour: the retrieval works but ce...

Thread safe C++ std::set that supports add, remove and iterators from multple threads

I'm looking for something similar to the CopyOnWriteSet in Java, a set that supports add, remove and some type of iterators from multiple threads. ...

Is this thread safe?

private static bool close_thread_running = false; public static void StartBrowserCleaning() { lock (close_thread_running) { if (close_thread_running) return; close_thread_running = true; } Thread thread = new Thread(new ThreadStart(delegate() { while (true) { lock (close_thread_running) { ...

Is Socket.SendAsync thread safe effectively?

I was fiddling with Silverlight's TCP communication and I was forced to use the System.Net.Sockets.Socket class which, on the Silverlight runtime has only asynchronous methods. I was wondering what happens if two threads call SendAsync on a Socket instance in a very short time one from the other? My single worry is to not have intermix...

Are BinaryFormatter Serialize and Deserialize thread safe?

Referencing this answer to a question. Can this be rewritten as: private static BinaryFormatter formatter = new BinaryFormatter(); public static T DeepClone<T>(this T a) { using(MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, a); stream.Position = 0; return (T)formatter.Deserialize(stream)...

Does the MSDN example usage of ReaderWriterLockSlim contain deadlock risk?

I'm using a ReaderWriterLockSlim to protect access to the cache on my ASP.NET application. MSDN has examples of using the lock. However this article http://www.nobletech.co.uk/Articles/ReaderWriterLockMgr.aspx has me worried about deadlocks. Is this really a risk? Should the MSDN documentation mention this? public string Read(int key) {...

When should I ask myself if my method is thread-safe or not?

Hi, When should I take it into consideration whether my method is thread-safe or not? thanks, kalem keki ...

Are C# arrays thread safe?

In particular Create a function to take an array and an index as parameters. Create a n element array. Create a n count loop. Inside the loop on a new thread assign a new instance of the object to the array using the indexer passed in. I know how to manage the threads etc. I am interested in know if this is thread safe way of doing...

Is it safe to access this variable from multiple threads?

I commonly write code that is along these lines: public class MyClass { static bool m_stop = false; public static void Main() { var th = new Thread(DoStuff); th.Start(); Console.ReadLine(); m_stop = true; th.Join(); } private static void DoStuff() { while( !m_stop ) { // do things here } } } ... and I a...

Is SecureRandom thread safe?

Is SecureRandom thread safe? That is, after initializing it, can access to the next random number be relied on to be thread safe? Examining the source code seems to show that it is, and this bug report seems to indicate that its lack of documentation as thread safe is a javadoc issue. Has anyone confirmed that it is in fact thread safe? ...

Thread safe lazy initializer; is swapping Func<>s a good idea?

The class at the bottom is an implementation of fast, thread safe, "lock free", lazy initializer. I say "lock free", although it isn't completely; It uses a lock until it is initialized, and then replaces the call to get the data with one that doesn't use the lock. (Similar to a double checked lock with a volatile member; and from perfo...

Is the Hessian class SerializerFactory thread-safe?

I'd like to use the Hessian (Java) serialization and need to create a SerializerFactory with custom serializers (to handle BigInteger). Can I create one of these and share it among threads? ...

Is this stored procedure thread-safe? (or whatever the equiv is on SQL Server)

With the help of others on SO I've knocked up a couple of Tables and Stored Procedures, this morning, as I'm far from a DB programmer. Would someone mind casting an eye over this and telling me if it's thread-safe? I guess that's probably not the term DBAs/DB developers use but I hope you get the idea: basically, what happens if this s...

Are standard output streams in C++ thread-safe (cout, cerr, clog)?

I know that there is no concept of threads in current C++, but this article is saying: A typesafe, threadsafe, portable logging mechanism ..... The fprintf() function is threadsafe, so even if this log is used from different threads, the output lines won't be scrambled. What about cout, cerr and clog? I think thi...

Schema validation error / Thread safety of XmlSchemaSet?

Good afternoon, An XML schema validation snippet is working fine on development/q&a environments, but is yielding some odd validation results in Production. The usual suspect would be that the code is unsafe for threading, and that the additional load of the Production scenario is flushing out the error. The exact scenario is as follow...

Are the new and delete operators thread-safe in pthreads-w32 for visual c++?

Are the new and delete operators thread-safe in pthreads-w32 for visual c++? What things should I assume will always be thread-safe in pthreads-w32? ...