thread-safety

VB.NET - Is this thread safe?

Let's say that I have a module that has a Queue in it. For other entities to Enqueue, they must go through a function: public sub InsertIntoQueue(Obj) MyQueue.Enqueue(Obj) end sub If I have multiple threads running and they want to call InsertIntoQueue(), is this considered thread safe? I am under the impression that there is on...

Request thread to quit without forcing it?

I am writing an app. There are plugins which DL resource from the net. If the user would like to quit i would not like any DLs to start but i would like DLs in progress to continue until done. After they stop i would gracefully quit. How do i find out if a thread is in a middle of a DL or just sleeping? The actual download resource func...

Rails threading - multiple tasks

Hi I am trying to run multiple tasks, each task access the database, and I am trying to run the tasks into separate execution wires. I played around, tried allow_concurrency which I have set to true, or config.thread_safe! but it I get un-deterministic errors, for example sometimes a class is missing, or a constant ... here is some c...

popen - locks or not thread safe?

I've seen a few implementations of popen()/pclose(). They all used a static list of pids, and no locking: static int *pids; static int fds; if (!pids) { if ((fds = getdtablesize()) <= 0) return (NULL); if ((pids = malloc(fds * sizeof(int))) == NULL) return (NULL); memset(pids, 0, fds * sizeof(int)); } O...

Unit test for thread safe-ness?

I've written a class and many unit test, but I did not make it thread safe. Now, I want to make the class thread safe, but to prove it and use TDD, I want to write some failing unit tests before I start refactoring. Any good way to do this? My first thought is just create a couple threads and make them all use the class in an unsafe w...

Is the following utility class thread-safe?

First let's look at the utility class (most javadoc has been removed to simply the example): public class ApplicationContextUtils { /** * The application context; care should be taken to ensure that 1) this * variable is assigned exactly once (in the * {@link #setContext(ApplicationContext)} method, 2) the context is...

Using static data access methods with the ADO.NET Entity Framework

Hi I am using the ADO.NET entity framework for the first time and the staticcode analysis is suggesting I change the following method to a static one as below. My question is simple, is this thread safe? public static void InsertUserDetails(UserAccount userAccount) { using (KnowledgeShareEntities entities = new Kno...

Is Gdiplus thread-safe?

I've perused the MSDN documentation and I couldn't find a statement one way or the other. What I'm interested in is: Can I call GdiplusStartup() on one thread and then use Gdiplus on another thread? Or do I need to call GdiplusStartup() for each thread? If I have a Bitmap object on thread 1 and different one on thread 2, can they bot...

Is it safe to dispose a JFrame from a different thread in Java?

Is it safe to call the dispose() method of a JFrame from a different thread (not the EDT)? ...

Lockfree standard collections and tutorial or articles.

Does someone know of a good resource for the implementation (meaning source code) of lock-free usual data types. I'm thinking of Lists, Queues and so on? Locking implementations are extremely easy to find but I can't find examples of lock free algorithms and how to exactly does CAS work and how to use it to implement those structures. ...

Is Java's TimeZone thread-safe?

I wanted my application to just have one TimeZone object which will be used by many SimpleDateFormat and Calendar objects from the other places concurrently. This is to avoid having to always do TimeZone.getTimeZone(ID). I know SimpleDateFormat and Calendar classes are not thread safe, which is why I configure one thread to always cr...

Are inmutable objects always threadsafe?

It is safe to assume that working with or passing around an immutable object would always be threadsafe? ...

Accessing object members and atomicity

We know from the C# specification that reference read/writes are atomic. In a statement that accesses member of an object, will the reference also be accessed atomically? I think yes because it is also a kind of implicit reference read which the compiler must provide atomicity for while generating code for it. In the same statement, ac...

Load multiple copies of a shared library

I am running Linux, and I would like to be able to make parallel function calls into a shared library (.so) which is unfortunately not threadsafe (I am guessing it has global datastructures). For performance reasons, I do not want to simply wrap the function calls in a mutex. What I would like to do is to spawn, say 4 threads, and also...

Thread Safety RijndaelManaged, ICryptoTransform.TransformFinalBlock?

Lets say we have this code that runs in the constructor: Dim initVectorBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(initVector) Dim saltValueBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(saltValue) Dim passPharse As String = GenerateKeyString(EncryptionKey) Dim password As Rfc2898DeriveBytes = New Rfc2...

How to create a thread-safe pool of objects?

In my server application (written in C#), I need to create a pool of same type of objects. I pull an object from pool when I need, and it goes back to pool when it is no longer needed. Mechanism needs to be thread safe since different threads will be asking and submitting these objects. I understand that frequently locking something to m...

Generate unique key in Java to be used as primary key in Oracle tables.

I am trying to get a string of length 15 to be used as primary key in database tables. The following code in java returns some key with length 35 UUID.randomUUID().toString() Can I change it to return a key of the length 15 ? How to ensure thread safety? Any help is greatly appreciated. ...

java wrapper around log4j logger and java.util.logging

I am writing a library. The library can be used by applications that use log4j loggers and java.util.logging loggers. So, I wrote a quick wrapper class, that encapsulates both loggers. I allow the application to set one or both loggers. And in my library I use the encapsulated class to print to either logger. My question is, since many...

Should I use SQLite for automatically build a list of banned IPs of comment spammers?

I am using a simple yet effective anti-spam system at a comments module which seems to be working flawlessly for more than a year now. Since it is capable of recognizing automated comment spam attempts, I am thinking of extending this security module with an ability of adding the offender IPs to a blacklist automatically. Do you think ...

C# put thread to sleep on dequeue?

I'm trying to use WebClient to download a bunch of files asynchronously. From my understanding, this is possible, but you need to have one WebClient object for each download. So I figured I'd just throw a bunch of them in a queue at the start of my program, then pop them off one at a time and tell them to download a file. When the file i...