thread-safety

VB.NET RaiseEvent, threadsafe?

Is RaiseEvent thread safe? In C# you write if (event != null) { event.invoke(); } and the C# code is not thread safe.... ...

Thread Safety in C

imagine I write a library in C. Further, imagine this library to be used from a multi-threaded environment. How do I make it thread-safe? More specific: How do I assure, that certain functions are executed only by one thread at a time? In opposite to Java or C# for example, C has no means to deal with threads/locks/etc., nor does the C ...

What does threadsafe mean?

Recently I tried to Access a textbox from a thread (other than the UI thread) and an exception was thrown, it said something about the "code not being thread safe" and so I ended up writing a delegate (sample from MSDN helped) and calling it instead. But even so I did'nt quite understand why all the extra code is necessary Update: Will...

ASP MVC - Comet/Reverse Ajax/PUSH - Is this code thread safe?

I'm trying to implement comet style features by polling the server for changes in data and holding the connection open untill there is something to response with. Firstly i have a static variable on my controller which stores the time that the data was last updated: public static volatile DateTime lastUpdateTime = 0; So whenever the ...

PHP: What does pcntl_fork() really do?

PHP's pcntl_fork funcion is supposed to fork a process just as the standard fork function in C. But I was wondering if this function really forks the process or if it emulates that behavior in a different way. If it really forks the process then it's clear which process that is: one of Apache's child processes. That's OK as long as Apach...

Lock-free thread-safe queue - need advice

Hi I need to design a thread-safe logger. My logger must have a Log() method that simply queues a text to be logged. Also a logger must be lock-free - so that other thread can log messages without locking the logger. I need to design a worker thread that must wait for some synchronization event and then log all messages from the queue...

Is this a safe version of double-checked locking?

Here's an idea I just came up with for a safe, efficient way of handling Singleton synchronization issues. It's basically double-checked locking, but with a twist that involves thread-local storage. In Java/C#/D-style pseudocode, assuming __thread denotes thread-local storage for static variables: class MySingleton { __thread stat...

openssl BF_cfb64_encrypt thread-safety

Is openssl's BF_cfb64_encrypt() thread safe? A sample code to use it to encrypt / decrypt a blob of data would be much appreciated. ...

Can a read-write conflict provokes an infinite loop?

Hi, Say there's a statement waiting for a variable to be updated by another thread. #in thread1: while (flag == 0); Without using any kind of lock, there might be a read-write conflict if one thread reads the variable while it's being updated by another one. #in thread2: flag = 1; Can this lead to an infinite loop? or is the conf...

SSRS Code Shared Variables and Simultaneous Report Execution

We have some reports that are failing when two of them are executed very close together. I've found out that if two instances of an SSRS report run at the same time, any Code variables declared at the class level (not inside a function) can collide. I suspect this may be the cause of our report failures and I'm working up a potential fi...

Are there any practical alternatives to threads?

While reading up on SQLite, I stumbled upon this quote in the FAQ: "Threads are evil. Avoid them." I have a lot of respect for SQLite, so I couldn't just disregard this. I got thinking what else I could, according to the "avoid them" policy, use instead in order to parallelize my tasks. As an example, the application I'm currently worki...

Are C# auto-implemented static properties thread-safe?

I would like to know if C# automatically implemented properties like "public static T Prop{get;set;}", are thread safe or not. Thanks! ...

Thread Synchronization in c#.net---Requirement Changed

Hey, I have a list of objects, for each object i want to run a totally separate thread (thread safty),like....i will pick one a object from my list in while loop and run a thread and then for next object run the next threads...all thread should be synchronized such that resources (values/connection (close/open) )shared by them s...

If Swing models' getters aren't thread-safe, how do you handle them?

It is well known that updating a Swing GUI must be done exclusively in the EDT. Less is advertised that reading stuff from the GUI must/should also be done in the EDT. For instance, let's take ButtonModel's isSelected() method, which tells (for instance) ToggleButton's state ("down" or "up"). In every example I've seen, isSelected() is...

is System.DirectoryServices.AccountManagement.GroupPrincipal thread safe?

I am writing a program that will create users in bulk, I have a operation that is part of the creation that is blocks for about 5 seconds, to get around this I was going to make it threaded and have everything sitting in a thread pool. My question is if I create the principle outside the thread and pass the group principle to the thread...

.NET Remoting thread locking mechanism

Hello all, I'm having a pressing issue and I'm hoping you all can help me out. I will try my best to explain it as well as I can. I am augmenting a system that uses .NET remoting to allow for database calls from a thin client to a server that executes said calls. The server itself has the data access components installed on it, so it...

Is this a valid pattern for raising events in C#?

Update: For the benefit of anyone reading this, since .NET 4, the lock is unnecessary due to changes in synchronization of auto-generated events, so I just use this now: public static void Raise<T>(this EventHandler<T> handler, object sender, T e) where T : EventArgs { if (handler != null) { handlerCopy(sender, e); }...

Is This a Good Design for Creating Thread-Safe Classes in C#?

Often, when I want a class which is thread-safe, I do something like the following: public class ThreadSafeClass { private readonly object theLock = new object(); private double propertyA; public double PropertyA { get { lock (theLock) { return propertyA; ...

How do I communicate between multiple threads?

I'm writing a plug-in for another program which uses the native program to open a series of files to extract some data from. One problem I am having is the process takes a long time and I want to keep the user interface from hanging. Plus I also want to give the user the ability to cancel the process before it completes. In the past I've...

Is Locking really needed in my iPhone application?

I'm working on a relatively simple iPhone application that has a multi-round Timer with a number of settings such as the number of rounds and round length. We allow certain settings to be upated while the timer is running which means the timer may be reading from the same memory that the settings are writing. There are no critical sect...