I'm using the ConcurrentDictionary and ConcurrentQueue classes from .NET 4 in the following code.
Is this code thread-safe? If not, how can I make it thread-safe?
public class Page
{
public string Name {get; set; }
}
public class PageQueue
{
private ConcurrentDictionary<int, ConcurrentQueue<Page>> pages =
new Concurren...
Is res_query (int res_query(const char *dname, int class, int type,unsigned char *answer,
int anslen);) thread-safe?
I think so, because it writes its answer to an user-allocated buffer (in contrast to gethostbyname that uses a statically allocated buffer).
Does somebody know for sure?
...
The ApplicationException constructor is an instance member so it is not guaranteed to be thread-safe. How do you know if the following code is completely unnecessary? When I say know, I mean is there something in the documentation that says this is unnecessary or have you seen the .NET source code and so you know it is unnecessary?
//...
I have wrote a simple web service in .NET which return a string value.
[WebMethod]
public string DeveloperInfo()
{
return "Chamara is the appliaction developer";
}
I need to consume it using a J2ME application.following is the code i have used
if (displayable == ServiceForm) {
if (command == exitCommand1) ...
In C#4 in a Nutshell, the author show that this class can write 0 sometimes without MemoryBarrier. I can´t reproduce in my Core2Duo:
public class Foo
{
int _answer;
bool _complete;
public void A()
{
_answer = 123;
//Thread.MemoryBarrier(); // Barrier 1
_complete = true;
//Thread.MemoryB...
The following code demonstrates my dilemma. The code creates a background thread which processes something, then Invokes the UI thread with the result.
It may throw an exception if the background thread calls Invoke on the form after the form has closed. It checks IsHandleCreated before calling Invoke, but the form might close after the...
I am trying to make a producer/consumer thread situation more efficient by skipping expensive event operations if necessary with something like:
//cas(variable, compare, set) is atomic compare and swap
//queue is already lock free
running = false
// dd item to queue – producer thread(s)
if(cas(running, false, true))
{
// We effect...
The guava-libraries have a class Ordering. I'm wondering if it's thread safe.
For example, can it be used as a static variable?
public static Ordering<String> BY_LENGTH_ORDERING = new Ordering<String>() {
public int compare(String left, String right) {
return Ints.compare(left.length(), right.length());
}
};
...
In a ASP.Net web application, when you have a stack intensive operation to run, a stackoverflow exception is thrown on IIS when the stack size crosses the IIS set limit of 256K. A regular winform application however has a limit of 1MB. So the exception would not occur when running the same operation in a Winform application.
There is no...
Can anybody please describe about how to implement threading in PHP programming? What I know for sure is that PHP does not support thread concept. However, please correct me if I'm wrong.
If possible, please try to provide some details with one example about PHP threading.
If possible, can anybody please also provide some details o...
Hi,
I want to read and write python-source-files from the file system in a thread-safe way.
open("n2.py","w").write(my_new_py_class)
from myproject import n2
#do something with n2
I assume that this is not thread-safe, since a request2 could modify the file before request1 is loading and executing it. I would like to achieve somethin...
So this is a continuation from my last question - So the question was
"What is the best way to build a program that is thread safe in terms that it needs to write double values to a file. If the function that saves the values via streamwriter is being called by multiple threads? Whats the best way of doing it?"
And I modified some code ...
I've got a thread (specifically an NSOperation) that runs to load some images for me for a scroll view when my main view asks for them. Any number of these NSOperations can be queued at once. So it goes with the filepath I give it and loads the image from the disk (as UIImages) and then sends the object back to my mainview by using perfo...
Hi,
I'm trying to implement a multi threaded, recursive file search logic in Visual C++. The logic is as follows:
Threads 1,2 will start at a directory location and match the files present in the directory with the search criteria. If they find a child directory, they will add it to a work Queue. Once a thread finishes with the files in...
I have a question for the Ioc gurus out there.
I am working with a co-worker to wrap our minds around Castle Windsor IoC. We are having a difference of opinion about static Domain Service objects within asp.Net webforms. We have a static factory called BLServiceFactory in our Infrastructure layer that retrieves the container.
public sea...
Lets say we have an object that can be accessed by multiple threads and a global singleton handing out the object's reference, also accessible by multiple threads.
class Book {
private string title;
public Book(string title) {
this.title = title;
}
public string Title { get { return title; } }
}
class Bookstore...
class Unit {
private readonly string name;
private readonly double scale;
public Unit(string name, double scale) {
this.name = name;
this.scale = scale,
}
public string Name { get { return name; } }
public string Scale { get { return scale; } }
private static Unit gram = new Unit("Gram", 1.0...
Hi,
I was wondering what is the 'correct' way to log information messages; to files, or to a special log in the event viewer?
I like logging to files since I can use rolling flat file listener and see fresh new log from each day, plus in the event viewer I can only see one message at a time - where in a file I can scan through the day m...
// Not thread-safe
class ShoppingCart {
private List<Product> products;
public void Add(Product p) { products.Add(p); }
public void Remove(Product p) { products.Remove(p); }
}
Whenever user triggers an action associated with shopping cart, we pull it out and do what is needed.
// Could be a HTTP GET or AJAX pull
Add(Produ...
I have been searching for resources to understand thread safety in java and came across this. Is there any popular/comprehensive resource or books that explains thread safety in a more simpler way, perhaps with more sample programs. I found the above resource hard to understand.
Thanks!
...