thread-safety

Is this a safe way to execute threads alternatively?

I would like to run code alternatively, so I could stop execution at any moment. Is this code safe? static class Program { static void Main() { var foo = new Foo(); //wait for interaction (this will be GUI app, so eg. btnNext_click) foo.Continue(); //wait again etc. foo.Continue(); ...

msdn: What is "Thread Safety"?

In many MSDN documents, this is written under the Thread Safety heading; "Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe." for example; here can someone explain it please in a rather simple way? Thank you :) ...

Thread safe mersenne twister

Looking for a thread safe random generator I found a mersenne twister generator class that the author says if thread safe: http://www.umiacs.umd.edu/~yangcj/mtrnd.html But after studying the code I cannot see were it is safe thread. There are no locks of any kind or anything resembling a lock variable in there. Is this implementation ...

Axis2, using Thread.sleep to do blocking

I am currently coding a Java WebService using axis2. However, one particular request needs me to do constant polling a status in another server for around 3-10 seconds time. I want to use Thread.sleep to do polling like every 500 mili for 3 seconds. Does it have any implication like performance issue or can anyone suggest a better idea...

How to make my data structure thread safe?

I defined an Element class: class Element<T> { T value; Element<T> next; Element(T value) { this.value = value; } } also defined a List class based on Element. It is a typical list, just like in any data structure books, has addHead, delete and etc operations public class List<T> implements Iterable<T> { ...

Is the MS DAAB 4.1 Database object threadsafe?

I've come across some code that has a singleton which creates / reuses a static instance of the MSDAAB Database object. Is the Database object threadsafe after creation? I couldn't find anything one way or the other in the MSDAAB docs. ...

Synchronizing access to a return value

Consider the following C++ member function: size_t size() const { boost::lock_guard<boost::mutex> lock(m_mutex); return m_size; } The intent here is not to synchronize access to the private member variable m_size, but just to make sure that the caller receives a valid value for m_size. The goal is to prevent the function f...

Is ucLibc malloc thread safe?

Is ucLibc malloc thread safe? ...

C# Singleton Logging Class

I am trying to figure out the best strategy for logging on the async-IO web server I am working on. I thought the easiest way was to have a singleton class that keeps Filestreams open for the appropriate log files so I could just do something like: Util.Logger.GetInstance().LogAccess(str); Or something like that. My class looks like ...

Curious about WinForm Control Thread Safety After Adding a Control on a Seperate Thread

I have a FileSystemWatcher set to pick up an picture that will be dropped in a particular directory. The way I was handling it was to add a PictureBox in code that is docked inside of a panel. I ran it, it blew up, and I realized that I was not handling the interaction with the controls on the main thread correctly. Here is the code: ...

ASP.NET A question about safety after writing some data to HtmlControl

Hi, I have a hidden input on my form, and my JavaScript code writes there dynamically generated string based on the user behavior on the page. Later, I access to that inpput via server side code. Many users will be using this page at the same time, so what about thread safety ? I mean, could it be possible that userA has an access to ...

Is the Java MessageFormat Class thread safe? (as opposed to SimpleThreadFormat)

I know that SimpleDateFormat and NumberFormat are NOT thread safe. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4101500 But what about the other Format classes like MessageFormat? Fortify 360 is flagging the use of "MessageFormat.format(String, Object...)" static method as a "Race Condition - Format Flaw" issue, but when I analyz...

Is there a threadsafe and generic IList<T> in c#?

Is List<T> or HashSet<T> or anything else built in threadsafe for addition only? My question is similar to http://stackoverflow.com/questions/1278010/threadsafe-and-generic-arraylist-in-c but I'm only looking for safety to cover adding to this list threaded, not removal or reading from it. ...

Why ThreadGroup is being criticised?

I'm aware of current practice of using Executors instead of ThreadGroup: generally preferred way to deal with Threads catching exceptions from threads, etc... However, what are the inherent flaws of ThreadGroup as such (I've heard a vague criticism for that class)? Thanks for answer. PS. this does not seem to answer this question. ...

Array of structs, multithreading, can I write at the same time to different indexes?

Hi I have an huge array which contains a struct "Tile". The program im writing is a 2D game, and I don't want different players (handled by different threads) to write their position to the same tile at the same time, and I wondered two things. Can two threads write to two different places in the array at the same time safely, and is th...

What to use instead of Interlocked.Equals

I have some legacy code that uses Interlocked.Equals to compare values. The values may be two bools or it may compare an array of structs to null. Resharper complains about Interlocked.Equals saying "access to a static member of a type via a derived type". I know that Equals is not a member of the Interlocked class, but rather is a mem...

CultureInfo thread safety

I have a multi-threaded application which parses some text and it needs to use English Culture Info for parsing numbers from this text. So, i do not want to create EngCulture everytime i call the parsing function. Currently i am passing EngCulture as a parameter but i am not happy with this. I want to define the EngCulture as a static me...

Is pushing a variable onto an array a threadsafe operation?

I have the following Perl code: push(@myArray, $myValue); Is the operation atomic, or will I need to use locks, if multiple threads will be performing this same operation on many threads? ...

Python: Thread safe dictionary with short lived keys, is this correct?

import threading import weakref _mainlock = threading.RLock() _job_locks = weakref.WeakValueDictionary() def do_thing(job_id): _mainlock.acquire() #Dictionary modification lock acquire _job_locks.setdefault(job_id, threading.RLock()) #Possibly modifies the dictionary _mainlock.release() _job_locks[job_id].acquire() tr...

How to successfully access and loop an ArrayList by multiple threads?

I need help in ArrayList. I have an arraylist of strings. I am looping through this list and sending them to the output stream one after the other. While I am looping through the list and sending them, it is possible that another thread will be adding some elements to it. After an element is sent, it must be removed from the list as well...