thread-safety

Thread safety and System.Text.Encoding in C#

Is it safe to use the same Encoding object from different threads? By "using" I mean, calling Encoding.GetString(), Encoding.GetBytes() and write some XML with an XmlWriter (created by something like XmlWriter.Create(myStream, new XmlWriterSettings() { Encoding = myEncoding }). The msdn site states that "Any instance members are not gu...

How to find out where a thread lock happened?

One of our company's Windows Forms application had a strange problem for several month. The app worked very reliable for most of our customers but on some PC's (mostly with a wireless lan connection) the app sometimes just didn't respond anymore. (You click on the UI and windows ask you to wait or kill the app). I wasn't able to track d...

Can NSTask safely be used outside the main thread?

Yesterday I read somewhere that NSTask isn't thread safe and that bothers me a lot, because I'm running a NSTask within a NSThread and is so far not experiencing any threading issues with it. My code is organized like this A: main thread -> B: worker thread -> C: worker task C: The worker task is a commandline program. B: The worker t...

Boost::Mutex & Malloc

Hi all, I'm trying to use a faster memory allocator in C++. I can't use Hoard due to licensing / cost. I was using NEDMalloc in a single threaded setting and got excellent performance, but I'm wondering if I should switch to something else -- as I understand things, NEDMalloc is just a replacement for C-based malloc() & free(), not th...

BlockingCollection(T) performance

For a while at my company we've used a home-grown ObjectPool<T> implementation that provides blocking access to its contents. It's pretty straightforward: a Queue<T>, an object to lock on, and an AutoResetEvent to signal to a "borrowing" thread when an item is added. The meat of the class is really these two methods: public T Borrow() ...

On thread safety in python using D-Bus asynchronous method calls

I write a python class which makes asynchronous method calls using D-Bus. When my reply_handler is called, it stores data in list. This list can be used by another class methods at the same time. Is it safe or I can use only synchronized data structures like Queue class? ...

is int? thread safe?

I know that in .net any 32bit type (int, bool, etc) are threadsafe. you know that there won't be a partial write ever (according to the spec). Does the same apply for int? (nullable int) ...

VB.net: Is my Thread Safe List Solution actually safe?

I've added the following Extensions to my Project in order to create a thread safe list: Extensions If I want to conduct a simple operation on my list <Extension()> _ Public Sub Action(Of T)(ByVal list As List(Of T), ByVal action As Action(Of List(Of T))) SyncLock (list) action(list) End SyncLock ...

What options do i have to make this code thread safe?

I have this segment of code , a lot of things skipped for brevity but the scene is this one: public class Billing { private List<PrecalculateValue> Values = new List<PrecalculateValue>(); public int GetValue(DateTime date) { var preCalculated = Values.SingleOrDefault(g => g.date == date).value; ...

Prevent cars in a 4 way junction from crashing in java

Hi, I have made a java application of a 4 way junction. I can to move all the cars across the junction using THread.sleep() but I need to make the cars not crash into one another. (See diagram) What should I use ? Synchronization wait()/notify()/notifyAll() ThreadPanels Canvas (btw what is Canvas and its purpose ?) I have used l...

Is TransactionScopeConnections in the data application block thread safe?

I have been studying the code for TransactionScopeConnections as I need to implement something similar and I am having trouble understanding the intent of the thread handling logic. In the method GetConnection transactionConnections is first locked to retrieve a list of connections and after the lock is released the list of connections i...

managing collections in memcached

I'm wondering about managing collections of data in memcached. I'm confused about how I maintain cache freshness/integrity when I have many levels of caching at work. Let's assume I have a hierarchy of cached data objects, for example, A represents the most atomic element of data, B represents a collection of 10 As C represents ...

How to traverse a binary tree in a thread safe way?

I need a way to traverse a binary tree, using multiple threads and store elements that matches a criteria into a list. How do I do that, in a thread safe way? ...

Thread-safe Controller and Utility Classes?

So I'm using Spring MVC and in my controller I call several Utility classes. Do the Collections I use in those utility classes need to be synchronized? Similarly, are multiple threads spawned for each user when they access my webpage in the controller meaning I need to ensure thread-safety? ...

urllib2 and cookielib thread safety

As far as I've been able to tell cookielib isnt thread safe; but then again the post stating so is five years old, so it might be wrong. Nevertheless, I've been wondering - If I spawn a class like this: class Acc: jar = cookielib.CookieJar() cookie = urllib2.HTTPCookieProcessor(jar) opener = urllib2.build_opener(coo...

How do you prevent adding duplicate values in a static ObservableCollection thread safe?

I'm not sure what to do as far as managing the _namePrefixes for this control. I know I can make it non-static, but it makes sense to be static to be consistent across all uses of this control in terms of content for my project. Also, I chose ObservableCollection because of the following scenario: I have 2 client machines, one for stand...

Tips to write thread-safe UNIX code?

What are the guidelines to write thread-safe UNIX code in C and C++? I know only a few: Don't use globals Don't use static local storage What others are there? ...

Designing a Thread Safe Class

When reading the MSDN documentation it always lets you know if a class is thread safe or not. My question is how do you design a class to be thread safe? I am not talking about calling the class with locking I am meaning I am working for Microsoft create XXX class\object and I want to be say it is "Thread Safe" what would I need to do? ...

Is this safe across threads?

I have some code that looks like this: Thread 0: CMyOtherClass *m_myclass; CMyClass::SomeFunc(DWORD SomeParam) { m_myclass = new CMyOtherClass(SomeParam); } Thread 1: CMyClass::InsideSecondThread() { MySecondThreadFunc(*m_myclass); } CMyClass::MySecondThreadFunc(MyOtherClass& myclass) { // do something with myclass varia...

Can objects instantiated within a static method be overwritten if the method is called on multiple threads?

If you retrieve an instance variable within a static method based on a parameter supplied to the static method, is it possible the instance variable can get stepped on if the static method is called at exactly the same time by different callers? The method I am calling is defined below and I am wondering if the instance variable invoice ...