thread-safety

Java StringBuilder and Thread Safety

I am building up a String out of multiple pieces and want to use either StringBuffer or StringBuilder to do so. From the Java 5 docs, I see that StringBuilder is preferred when possible, with the caveat that "Instances of StringBuilder are not safe for use by multiple threads". From this statement I understand that I should not have a si...

Suggestions for writing an nsapi plugin that calls sybase, that has to be threadsafe

I'm having a hell of a time trying to find sybase documentation that says if the 12.5 client is thread safe. I need to make sybase threadsafe calls because I'm writing an nsapi plugin which lives in a threaded environment. So either I need to make sure the sybase client can run in a threaded environment or I'd need to serialize calls to ...

C# Question about thread safety

I'm using a threadpool to do some heavy processing and also bits of sql. Currently I open sql connections when I need them, run a query and then close them. This works fine. The application has been running with no issues. As more work is being done by this application it's using more threads. More threads mean more opening/closing of SQ...

Is this a bad practice with static classes and thread safety?

Assuming I'm not using the lock statement, is this a bad practice? public static class Foo { public static string Bar() { bool working; while (working) { // Loop until ready to run. } working = true; // Do stuff here. working = false; return "done." } } Edit - After trying something lik...

Ruby/Rails thread safety

I have been hacking with Ruby from time to time, but I haven't done anything big or multithreaded with it. I have heard that MRI only supports green threads and JRuby supports native threads via JVM. However, I stumble upon comments on blogs and discussion groups which say that "Rails is not thread-safe" or that Ruby itself is not thread...

Running a non-thread-safe dll in a multithreading windows http server

I need to encapsulate a VB6 application as a COM object that will be called by IIS. One of the dlls used by the VB6 app is NOT thread-safe. How can I make sure that whenever my COM object is called it doesn't share the same dll with other instances of itself? I read somewhere that ActiveX exes run each instance in a different process,...

How to implement a thread safe timer on linux?

As we know, doing things in signal handlers is really bad, because they run in an interrupt-like context. It's quite possible that various locks (including the malloc() heap lock!) are held when the signal handler is called. So I want to implement a thread safe timer without using signal mechanism. How can I do? Sorry, actually, I'm n...

Can EventActionDispatcher publish "this" before the constructor finishes?

The recommended way to use the EventActionDispatcher is as follows (per the API docs @ http://struts.apache.org/1.2.9/api/org/apache/struts/actions/EventActionDispatcher.html ) public class MyCustomAction extends Action { protected ActionDispatcher dispatcher = new EventActionDispatcher(this); public ActionForward exe...

Are .NET ref parameters thread-safe, or vulnerable to unsafe multithreaded access?

Edit for intro: We know that a ref parameter in C# passes a reference to a variable, allowing the external variable itself to be changed within a called method. But is the reference handled much like a C pointer (reading the current contents of the original variable with every access to that parameter and changing the original variable ...

Is it possible to post code taken from the .net framework and modified online?

I used reflector to view the code of the generic dictionary collection (Dictionary<TKey, TValue>) and modified that code to make it thread safe. I want to post this code on my blog so others can review it (and tell me if I did something wrong) and also use it in their projects if they want. Legally speaking, am I allowed to do so? I modi...

Is PHP thread-safe

Is PHP (as of 5.2) thread-safe on Linux/UNIX? Would it be possible to use it with Apache Worker-MPM or Event-MPM? The facts I gathered so far are inconclusive: default binaries included in most distributions have ZTS disabled, so I aware, that I'd have to recompile them. in theory Zend Engine (core PHP) with ZTS enabled is thread...

Tool for detecting concurrency problems

I saw a tool which can tell you if you have design problem in your project and I'm wondering if there is a tool which can tell you dynamically if there are some concurrency problems in your project. ...

Is boost shared_ptr <XXX> thread safe?

I have a question about boost :: shared_ptr. There are lots of thread. class CResource { xxxxxx } class CResourceBase { public: void SetResource(shared_ptr<CResource> res) { m_Res = res; } shared_ptr<CResource> GetResource() { return m_Res; } private: shared_ptr<CResource> m_Res; } CResourceBase base; ...

Is boost shared_ptr<XX> thread-safe?

Is the following code thread safe when using boost shared_ptr. Thanks! class CResource { xxxxxx } class CResourceBase { CResourceBase() { m_pMutex = new CMutex; } ~CResourceBase() { ASSERT(m_pMutex != NULL); delete m_pMutex; m_pMutex = NULL; } private: CMutex *m_pMutex; public: void SetResource(shared_ptr<CResource> res) { CS...

Static data in an ASP.NET page - threadsafe?

The background to this question is that I need to use some user session data in a (static) WebMethod. I have created a static property that references the data I need like so: private static UserWebSession UserWebSession { get { return (UserWebSession)HttpContext.Current.Session["UserWebSession"]; } } I can then ca...

Why is C# List<> not thread-safe?

from this site: http://crfdesign.net/programming/top-10-differences-between-java-and-c Unfortunately, List<> is not thread-safe (C#’s ArrayList and Java’s Vector are thread-safe). C# also has a Hashtable; the generic version is: what makes List<> not thread-safe? is it implementation problem on .net framework engineer's part...

Can file pointer change during the process of write or read of a CFile object

I have a CFile object, which can be accessed by multiple threads. There is the possibility that one thread is writing data to this file while another thread is reading data from the file. I want to know is there any unsafety under this policy? Can the file pointer change before the write or read process complete? Is the answer is yes, ho...

Is List<T>.Contains() a Threadsafe call - C#

My understanding is that if you are using a generic list (List) in C#, that it can support multiple concurrent readers but only one writer. And when you introduce a writer into the mix, you must also provide synchronization constructs to make the operations thread safe. Is List.Contains considered a read operation? In other words, i...

Are inline functions in C/C++ a way to make them thread-safe?

I make the following reasoning, please tell me what's wrong (or right) about it: "If inlining a function duplicates the code in the place the function is called, then the static and local variables are duplicated for each function calling it and if there is only one thread running the function that calls the inlined one at the same time...

Primitive synchronization primitives -- safe?

On constrained devices, I often find myself "faking" locks between 2 threads with 2 bools. Each is only read by one thread, and only written by the other. Here's what I mean: bool quitted = false, paused = false; bool should_quit = false, should_pause = false; void downloader_thread() { quitted = false; while(!should_quit) { ...