thread-safety

Ramifications of CheckForIllegalCrossThreadCalls=false

I recently updated an application from VS2003 to VS2008 and I knew I would be dealing with a host of "Cross-thread operation not valid: Control 'myControl' accessed from a thread other than the thread it was created on" I am handling this in what I beleive is the correct way (see code sample below). I am running into numerous controls th...

Is it possible or reasonable to implement the double-checked locking in Delphi?

As I known, there are two common kinds of practices to ensure the thread safety of lazy-initialization: Double-checked locking (Marks the variable as volatile to avoid the memory ordering) InterlockedCompareExchangePointer It seems VCL uses the second practice. Is there any reason? class function TEncoding.GetUTF8: TEncoding; var ...

If I'm updating a DataRow, do I lock the entire DataTable or just the DataRow?

Suppose I'm accessing a DataTable from multiple threads. If I want to access a particular row, I suspect I need to lock that operation (I could be mistaken about this, but at least I know this way I'm safe): // this is a strongly-typed table OrdersRow row = null; lock (orderTable.Rows.SyncRoot) { row = orderTable.FindByOrderId(myOrd...

Thread safe lockfree mutual ByteArray queue

A byte stream should be transferred and there is one producer thread and a consumer one. Speed of producer is higher than consumer most of the time, and I need enough buffered data for QoS of my application. I read about my problem and there are solutions like shared buffer, PipeStream .NET class ... This class is going to be instantiate...

Is this a valid, lazy, thread-safe Singleton implementation for C#?

I implemented a Singleton pattern like this: public sealed class MyClass { ... public static MyClass Instance { get { return SingletonHolder.instance; } } ... static class SingletonHolder { public static MyClass instance = new MyClass (); } } From Googling around for C# Singleton implementat...

Threads and select mixing in ruby

Hello, The Ruby framework I am using provides a TcpServer class which, surprisingly, establishes a TcpServer. It has two threads - one monitors with Kernel.select the listener thread and dispatches a on_client_connect(fd) method and the other monitors established connections and dspatches on_client_data(fd). I want to use the TcpServer...

Accidental Complexity in OpenSSL HMAC functions

SSL Documentation Analaysis This question is pertaining the usage of the HMAC routines in OpenSSL. Since Openssl documentation is a tad on the weak side in certain areas, profiling has revealed that using the: unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d, int n, ...

Is DataRow thread safe? How to update a single datarow in a datatable using multiple threads? - .net 2.0

Hello all I want to update a single datarow in a datatable using multiple threads. Is this actually possible? I've written the following code implementing a simple multi-threading to update a single datarow. I get different results each time. Why is it so? public partial class Form1 : Form { private static DataTable dtMain; pr...

Writing re-entrant lexer with Flex

I'm newbie to flex. I'm trying to write a simple re-entrant lexer/scanner with flex. The lexer definition goes below. I get stuck with compilation errors as shown below (yyg issue): reentrant.l: /* Definitions */ digit [0-9] letter [a-zA-Z] alphanum [a-zA-Z0-9] identifier [a-zA-Z_][a-zA-Z0-9_]+ integer ...

Android threading and database locking

Hi, We are using AsyncTasks to access database tables and cursors. Unfortunately we are seeing occasional exceptions regarding the database being locked. E/SQLiteOpenHelper(15963): Couldn't open iviewnews.db for writing (will try read-only): E/SQLiteOpenHelper(15963): android.database.sqlite.SQLiteException: database is locked E/SQLit...

Is commons-exec thread-safe?

Is Apache Commons Exec a thread-safe library? ...

Java: is Exception class thread-safe?

As I understand, Java's Exception class is certainly not immutable (methods like initCause and setStackTrace give some clues about that). So is it at least thread-safe? Suppose one of my classes has a field like this: private final Exception myException; Can I safely expose this field to multiple threads? I'm not willing to discuss co...

C# - Which is more efficient and thread safe? static or instant classes?

Consider the following two scenarios: //Data Contract public class MyValue { } Scenario 1: Using a static helper class. public class Broker { private string[] _userRoles; public Broker(string[] userRoles) { this._userRoles = userRoles; } public MyValue[] GetValues() { return BrokerHelper.GetV...

Returning pointers in a thread-safe way.

Assume I have a thread-safe collection of Things (call it a ThingList), and I want to add the following function. Thing * ThingList::findByName(string name) { return &item[name]; // or something similar.. } But by doing this, I've delegated the responsibility for thread safety to the calling code, which would have to do something li...

Java static and thread safety or what to do

I am extending a library to do some work for me. Here is the code: public static synchronized String decompile(String source, int flags,UintMap properties,Map<String,String> namesMap) { Decompiler.namesMap=namesMap; String decompiled=decompile(source,flags,properties); Decompiler.namesMap=null; retur...

java and threads: very strange behaviour

private synchronized Map<Team, StandingRow> calculateStanding() { System.out.println("Calculate standing for group " + getName()); Map<Team, StandingRow> standing = new LinkedHashMap<Team, StandingRow>(); for (Team team : teams) { standing.put(team, new StandingRow(team)); } ...

Simple C++ container class that is thread-safe for writing

I am writing a multi-threaded program using OpenMP in C++. At one point my program forks into many threads, each of which need to add "jobs" to some container that keeps track of all added jobs. Each job can just be a pointer to some object. Basically, I just need the add pointers to some container from several threads at the same tim...

Is a HashMap thread-safe for different keys?

If I have two multiple threads accessing a HashMap, but guarantee that they'll never be accessing the same key at the same time, could that still lead to a race condition? ...

Is thread-safe to use the 'yield' operator inside an extension method'?

Would be thread-safe to use the yield operator inside an extension method? For example: public static IEnumerable<CartItem> GetItems( this Cart cart ) { { while( cart.hasNext() ) yield return cart.GetNextItem( ); } } ...

ID generator with local static variable - thread-safe?

Will the following piece of code work as expected in a multi-threaded scenario? int getUniqueID() { static int ID=0; return ++ID; } It's not necessary that the IDs to be contiguous - even if it skips a value, it's fine. Can it be said that when this function returns, the value returned will be unique across all threa...