Say that I have
public static class M
{
public static string Concat(string a, string b)
{
return N.AddOne(a, b);
}
public static string Concat2(string a, string b)
{
return SomeThreadSafeMethod(a, b);
}
}
public static class N
{
public static string AddOne(string a, string b)
{
retur...
I have a class that maintains a private Dictionary instance that caches some data.
The class writes to the dictionary from multiple threads using a ReaderWriterLockSlim.
I want to expose the dictionary's values outside the class.
What is a thread-safe way of doing that?
Right now, I have the following:
public ReadOnlyCollection<MyCla...
Given:
void getBlah() {
static Blah* blah = new Blah();
return blah;
}
In a multi threaded setting, is it possible that new Blah() is called more than once?
Thanks!
...
We added DynamicProxy to our ASP.NET web app a couple of weeks ago. The code ran fine in dev and QA, but when we pushed to production, we got the following exception (top of stack trace only):
[ArgumentNullException: Invalid internal state.]
System.Reflection.Emit.TypeBuilder._InternalSetMethodIL(Int32 methodHandle, Boolean isInitLoca...
I'm seeing an issue in a production ASP.NET application that involves the following code, which is used to render the geocoordinates of a particular object:
private double _longitude;
private double _latitude;
public string ToCsvString()
{
return _latitude + "," + _longitude;
}
Thread.CurrentThread.CurrentCulture will be set to d...
Let's say I have two arrays:
int[] array1 = new int[2000000];
int[] array2 = new int[2000000];
I stick some values into the arrays and then want to add the contents of array2 to array1 like so:
for(int i = 0; i < 2000000; ++i) array1[i] += array2[i];
Now, let's say I want to make processing faster on a multi-processor machine, so i...
I'd like to deploy my Django app (which uses postgresql as database) on lighttpd using FastCGI.
For postgresql i see that Django has 2 backends available 'postgresql_psycopg2' and 'postgresql'.
My question is that lighttpd being a threaded server are there any issues with any of this backends? Are they thread safe? And which one of them ...
Suppose I have a model Animal. Animals have a field species which can either be "Lion" or "Dolphin".
The AnimalAdmin should have two views, add_lion_view() and add_dolphin_view(), which call the standard add_view() method after making sure that either species is going to be added.
I used to do this by setting the an AnimalAdmin instan...
I'm planning to design a class to limit the execution of a function to given amount within the specified time, for example:
Process max. 5 files in 1 second
It should be thread-safe and performance hit should be minimal.
How would you design such a class? I've got couple of ideas but none of them seemed right to me.
Is there any ...
I have two threads, and I want to make sure I am doing the synchronization correctly on the LinkedBlockingQueue.. Is this correct? Or is the explicit synchronization on (messageToCommsQueue) not necessary?
Declaration:
private LinkedBlockingQueue<BaseMessage> messagesToCommsQueue;
Method one:
private void startOperationModeSta...
Now from what I understand under Perl ithreads all data is private unless explicitly shared.
I want to write a function which stores per thread state between calls. I assume that a side effect of all data being thread private by default would allow me to use a closure like this:
#!/usr/bin/perl -w
use strict;
use threads;
{ # closur...
I am writing a shared library that will allow linked applications to query a resource.
The resource class is implemented with only static methods (see below). It also uses a global object (well scoped in an anonymous namespace). The reason for the global variable is that I do not want to expose users of the library to the internals of t...
The scenario I am facing is as below. Because ThreadPool is 1 instance per process so my question is that would method 1 cancel tasks queued by method 2 after 3 seconds?
http request comes in
*method 1 gets executed first*:
ThreadPool.QueueUserWorkItem x 3
WaitHandle.WaitAll for 3 seconds
*method 2 gets executed after method 1...
I am writing a cataloging application that parses through and extracts information from files and stores the information from each file in an object instance. In addition to the data extracted from the file the objects also have additional meta data properties (author, tags, notes, etc..) which later get stored in a separate XML file.
E...
I am a threading noob and I am trying to write a custom thread safe generic list class in C# (.NET 3.5 SP1). I've read Why are thread safe collections so hard?. After reviewing the requirements of the class I think I only need to safely add to the list and return the list. The example shows pretty much all I want except it lacks the retu...
I'm having a problem unit testing a class which fires events when a thread starts and finishes. A cut down version of the offending source is as follows:
public class ThreadRunner
{
private bool keepRunning;
public event EventHandler Started;
public event EventHandler Finished;
public void StartThreadTest()
{
...
I asked a question about building custom Thread Safe Generic List now I am trying to unit test it and I absolutely have no idea how to do that. Since the lock happens inside the ThreadSafeList class I am not sure how to make the list to lock for a period of time while I am try to mimic the multiple add call. Thanks.
Can_add_one_item_at_...
#define atomicAdd OSAtomicAdd32Barrier
class PtrInterface: public Uncopyable {
private:
typedef volatile int RefCount;
mutable RefCount rc;
public:
inline void newRef() const { atomicAdd(1, &rc); }
inline void deleteRef() const { atomicAdd(-1, &rc); }
};
[This is the basis of an invasive refcounted pointer; I just ...
If a servlet is not thread safe, then does that mean that all objects created and referenced during the servlet lifecycle are not thread safe? Maybe I'm not quite getting this, but in Web applications you almost always want to account for data stored during the servlet lifecycle that is pertinent to a single user's request. What are some...
More specifically, is List(T)(IEnumerable(T)) thread-safe if the IEnumerable used to initialize the list is modified during the construction of the new list?
...