thread-safety

Is there a way to change the JPA fetch type on a method?

Is there a way to change the JPA fetch type on a single method without editing the entity object? I have a shared ORM layer consisting of JPA entity classes. This ORM layer is accessed by two DAO layers. One DAO needs lazy fetching, as it is for my web application, the other needs eager fetching, as I need it to be threadsafe. Here is ...

Thread-safe static variables without mutexing?

I remember reading that static variables declared inside methods is not thread-safe. Dog* MyClass::BadMethod() { static Dog dog("Lassie"); return &dog; } My library generates C++ code for end-users to compile as part of their application. The code it generates needs to initialize static variables in a thread-safe cross-platform ma...

Locking a self-loading cache

I'm implementing a simple cache in C#, and trying to make it accessible from multiple threads. In the basic read case, it's easy: var cacheA = new Dictionary<int, MyObj>(); // Populated in constructor public MyObj GetCachedObjA(int key) { return cacheA[key]; } This is, I believe, completely thread-safe. But I'd also like to make ...

Please help me make this code thread safe

I've got a bit of a problem with making my data loading and filtering thread safe. The following code on my control's base class which handles all the data population through a BackgroundWorker. This tends to throw the error on "this.DataWorker.RunWorkerAsync()" saying that the BackgroundWorker is busy. /// <summary> /// Handles the po...

Is this a thread safe way to initialize a [ThreadStatic] ?

[ThreadStatic] private static Foo _foo; public static Foo CurrentFoo { get { if (_foo == null) { _foo = new Foo(); } return _foo; } } Is the previous code thread safe? Or do we need to lock the method? ...

Java ReentrantReadWriteLock requests

Just a quick question about ReadWriteLocks in Java (specifically the ReentrantReadWriteLock implementation) as I don’t find the sun documentation clear. What happens if a read lock is held by a thread when a write lock is requested by another? Does the write lock thread have to wait for all currently held read-locks to be released? Als...

Threadsafe Vector class for C++

Does anyone know a quick and dirty threadsafe vector class for c++? I am multithreading some code, and I believe the problem I have is related to the way the vectors are used. I plan to rewrite the code, but before I go crazy redoing the code, I would like to test it with a threadsafe vector to be sure. I also figure if such a thing i...

Static methods and thread safety

In python with all this idea of "Everything is an object" where is thread-safety? I am developing django website with wsgi. Also it would work in linux, and as I know they use effective process management, so we could not think about thread-safety alot. I am not doubt in how module loads, and there functions are static or not? Every inf...

What can I attach to pylons.request in Pylons?

I want keep track of a unique identifier for each browser that connects to my web application (that is written in Pylons.) I keep a cookie on the client to keep track of this, but if the cookie isn't present, then I want to generate a new unique identifier that will be sent back to the client with the response, but I also may want to ac...

Simple thread-safe non-blocking file logger class in c#

I have a web application, that will log some information to a file. I am looking for a simple thread-safe non-blocking file logger class in c#. I have little experience with threading. I known there are great logging components out there like log4Net, Enterprise Library Logging Block, ELMAH, but I do not want an external dependence for m...

Are Generators Threadsafe?

I have a multithreaded program where I create a generator function and then pass it to new threads. I want it to be shared/global in nature so each thread can get the next value from the generator. Is it safe to use a generator like this, or will I run into problems/conditions accessing the shared generator from multiple threads? If...

Execute a delegate in the ui thread (using message pump).

I have a background thread that handles communication with an external service. Each time the background thread receives a message I'd like to pass it to the UI thread for further processing (displaying to user). Currently I've made a thread safe message queue that is pooled periodically in Timer.Tick and filled in background thread. Bu...

boost::shared_ptr and multithreaded access

Hi! I'm trying to implement a multithreaded framework, in which output objects are created at the end of every frame that my networking thread runs, so that another thread can, at the beginning of its frame, obtain the most recent "completed output" pointer and know that it has safe and complete read-only access to any data stored withi...

System.InvalidOperationException: Collection was modified ...

I am getting a following exception while enumerating through a queue: System.InvalidOperationException: Collection was modified; enumeration operation may not execute here is the code excerpt: 1: private bool extractWriteActions(out List<WriteChannel> channelWrites) 2: { 3: channelWrites = new List<WriteChannel>()...

What object should I lock on when I am passing a Collection<Foo> into a separate class ?

Please refer to UML The Connection class's constructor initializes its foos member via foos = Collections.synchronizedList( new ArrayList<Foo>(10) ); When Connection#start() is invoked, it creates an instance of Poller (while passing the foos reference into Poller's constructor) & Poller is started (Poller is a Runnable). Question: ...

Loadtesting vs Threading

i am running iis 7 with .net 3.5 sp1 Can anyone tell me if this is thread safe since it keeps on failing under high load of users private static void addQueryStringParameters(XElement inputs) { NameValueCollection qs = HttpContext.Current.Request.QueryString; XElement queryStringParameters = new XElement("QueryStringParameters...

Redirecting to a new page in Asp.Net with several thechniques - what will happen to the thread you were running it in the prev. page?

Hi I know there is several ways to change the current page in ASP.Net. So, by Redirecting to a new page, what will happen to the thread we were running it in the prev. page? ...

Python: is os.read() / os.write() on an os.pipe() threadsafe?

Hello! Consider: pipe_read, pipe_write = os.pipe() Now, I would like to know two things: (1) I have two threads. If I guarantee that only one is reading os.read(pipe_read,n) and the other is only writing os.write(pipe_write), will I have any problem, even if the two threads do it simultaneously? Will I get all data that was written ...

Why might threads be considered "evil"?

I was reading the SQLite FAQ, and came upon this passage: Threads are evil. Avoid them. I don't quite understand the statement "Thread are evil". If that is true, then what is the alternative? My superficial understanding of threads is: Threads make concurrence happen. Otherwise, the CPU horsepower will be wasted, waiting for (...

Is this code thread-safe?

This is a simplified version of some code I'm currently maintaining: int SomeFunc() { const long lIndex = m_lCurrentIndex; int nSum = 0; nSum += m_someArray[lIndex]; nSum += m_someArray[lIndex]; return nSum; } lCurrentIndex is updated periodically by another thread. The question is; will making a local copy of m_CurrentInd...