thread-safety

How to Invoke on background thread

Is there a way to invoke a method on a background thread ? I am aware of BackgroundWorker/Creating a thread or use ThreadPool.QueueUserWorkItem etc but that's not the answer i am looking for for e.g. the SCSF has attributes to ensure the method is invoked on a background or a UI thread I'd like to do something similar for a small app ...

Threadsafe way to add and remove items from list in .Net

I want to add items to a list from one thread and from another thread remove items from the same list. However, I am not sure if I will run into problems with multiple threads accessing the same object. I have read a bit on the lock statement but I am not sure how to implement this. In short, the question is, how do I ensure thread safe...

Is MySQL Connector/JDBC thread safe?

Is the standard MySQL JDBC driver thread-safe? Specifically I want to use a single connection across all threads, but each statement will only be used in a single thread. Are there certain scenarios that are safe and others that aren't? What's your experience here? ...

Multiple-writer thread-safe queue in C

I am working on a multi-threaded C application using pthreads. I have one thread which writes to a a database (the database library is only safe to be used in a single thread), and several threads which are gathering data, processing it, and then need to send the results to the database thread for storage. I've seen in mentioned that it ...

Threaded application + IntegrityError

Hi, I have python threaded application + Postgres. I am using Django's ORM to save to Postgres.. I have concurrent save calls. Occasionally 2 threads save with the same primary key which leads to an issue. Postgres log: ERROR: duplicate key value violates unique constraint "store_pkey" STATEMENT: INSERT INTO "store" ("store_id", "ad...

Portable thread-safety in C?

Purpose I'm writing a small library for which portability is the biggest concern. It has been designed to assume only a mostly-compliant C90 (ISO/IEC 9899:1990) environment... nothing more. The set of functions provided by the library all operate (read/write) on an internal data structure. I've considered some other design alternatives,...

Java concurrency : Making webservice access threadsafe

Hi I'd like to know the correct / best way to handle concurrency with an Axis2 webservice. Eg, given this code: public class MyServiceDelegate { @Resource UserWebService service; // Injected by spring public CustomerDTO getCustomer() { String sessionString = getSessionStringFromCookies(); service.setJSES...

Do I need to lock or mark as volatile when accessing a simple boolean flag in C#?

Lets just say you have a simple operation that runs on a background thread. You want to provide a way to cancel this operation so you create a boolean flag that you set to true from the click event handler of a cancel button. private bool _cancelled; private void CancelButton_Click(Object sender ClickEventArgs e) { _cancelled = tru...

Retaining an object created in an NSThread

I have the following method which is spawned by a call for a new thread (using NSThread): - (void) updateFMLs { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSArray *temp = [[NSArray alloc] initWithArray:someArrayFromAnotherProcess]; [self performSelectorOnMainThread:@selector(doneLoading:) withObject:temp...

Can I use a non-threadsafe library in a multi-user .NET web application?

For a new web application project using .NET, an existing library (written in C#) will be made available online which performs some calculations on information in a data model. The library needs to be accessed by many users at the same time. Every user will work with a different set of data. Users also can modify model data and repeat t...

ReaderWriterLockSlim implements single writer, or requires single writer?

I think I am having a brain fart. This sould be a very simple question: does ReaderWriterLockSlim IMPLEMENT the single writer concept, or does it REQUIRE a single writer thread? ...

Modify locked object within lock block

I'm having thread contention in an OLTP app. While reviewing the code involved, I found the following: lock (_pendingTransactions) { transaction.EndPointRequest.Request.Key = (string)MessageComparer.GenerateKey(transaction.EndPointRequest.Request); if (!_pendingTransactions.ContainsKey(transactio...

Is the StateMachine on Windows WorkFlow Thread Safe?

Hello I am planning to use the State Machine WorkFlow of Windows Workflows. The state machine will be receiving events from two separate threads, the state machine of course will both change its state and execute actions based on its current state and the event that came in. My question is, is the state machine of windows workflow thr...

Is Delphi's TADOConnection thread-safe?

I'm writing a Delphi 7 application which needs to access the same SQL Server database from many different threads simultaneously. Can I use a single shared TADOConnection, or must each thread create their own? ...

What makes instance members thread-unsafe vs public static?

So we've all seen the Threading notification on MSDN for many available generic objects: "Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe." My question is, what is it about being an instance variable vs a public static makes it unsafe? ...

Lock a winforms control

I need to ensure that, once the execution hits a method, the control received by this method is not changed by another thread. Basically, I thought in something like this: private void doSomeWork(Control control) { lock (control) { // do some stuff with the control... } } Is this a bad idea? Edit: Actually, what I'm ...

I need to create a Thread-safe static variable in C# .Net

ok, its a little more complicated than the question. class A { static int needsToBeThreadSafe = 0; public static void M1() { needsToBeThreadSafe = RandomNumber(); } public static void M2() { print(needsToBeThreadSafe); } } now i require that between M1() and M2() calls 'needsToBeThreadSafe' stays Threa...

Thread-safe memoization

Let's take Wes Dyer's approach to function memoization as the starting point: public static Func<A, R> Memoize<A, R>(this Func<A, R> f) { var map = new Dictionary<A, R>(); return a => { R value; if (map.TryGetValue(a, out value)) return value; value = f(a); map.Add(a, value); return value; ...

Is this code thread-safe? How can I make it thread-safe? (C#)

I have a WCF service with a security class for getting some of the attributes of the calling user. However I'm quite bad when it comes to thread safety - to this point, I haven't needed to do much with it, and only have a rudimentary theoretical understanding of the problems of multi-threading. Given the following function: public clas...

How deep does a lock go?

I have the following code: locker = new object(); lock (locker) { for (int i = 0; i < 3; i++) ver_store[i] = atomic_Poll(power); } I was just wandering, considering the function within the lock accesses some global resources, (an open socket among them) ...