thread-safety

Is this use of PreparedStatements in a Thread in Java correct?

I'm still an undergrad just working part time and so I'm always trying to be aware of better ways to do things. Recently I had to write a program for work where the main thread of the program would spawn "task" threads (for each db "task" record) which would perform some operations and then update the record to say that it has finished. ...

C# Random Number Generator getting stuck in a cycle

Hi, I am using .NET to create an artificial life program and I am using C#'s pseudo random class defined in a Singleton. The idea is that if I use the same random number generator throughout the application, I could merely save the seed and then reload from the seed to recompute a certain interesting run. public sealed class RandomNumbe...

Lightweight spinlocks built from GCC atomic operations?

I'd like to minimize synchronization and write lock-free code when possible in a project of mine. When absolutely necessary I'd love to substitute light-weight spinlocks built from atomic operations for pthread and win32 mutex locks. My understanding is that these are system calls underneath and could cause a context switch (which may be...

How do I refactor this IEnumerable<T> to be thread-safe?

I am looking at Skeet's AtomicEnumerable but I'm not sure how to integrate it into my current IEnumerable exmaple below (http://msmvps.com/blogs/jon_skeet/archive/2009/10/23/iterating-atomically.aspx) Basically I want to foreach my blahs type in a thread-safe way. thanks so .. foreach on multiple threads ... giving correct order Bl...

Transactional isolation level needed for safely incrementing ids

I'm writing a small piece of software that is to insert records into a database used by a commercial application. The unique primary keys (ids) in the relevant table(s) are sequential, but does not seem to be set to "auto increment". Thus, I assume, I will have to find the largest id, increment it and use that value for the record I'm in...

C++ Thread Safe Integer

Hello everyone, I have currently created a C++ class for a thread safe integer which simply stores an integer privately and has public get a set functions which use a boost::mutex to ensure that only one change at a time can be applied to the integer. Is this the most efficient way to do it, I have been informed that mutexes are quite ...

How to find a particular dll is threadsafe or not ? Ant API/tool for this?

For example, i downloaded Gecko 1.9.1 SDK. It contains js3250.dll. How i can be sure that this dll is thread-safe? Advance Thanks -Parimal Das ...

python iterators and thread-safety

I have a class which is being operated on by two functions. One function creates a list of widgets and writes it into the class: def updateWidgets(self): widgets = self.generateWidgetList() self.widgets = widgets the other function deals with the widgets in some way: def workOnWidgets(self): for widget in self.widgets: ...

C# struct with object as data member

As we know, in C# structs are passed by value, not by reference. So if I have a struct with the following data members: private struct MessageBox { // data members private DateTime dm_DateTimeStamp; // a struct type private TimeSpan dm_TimeSpanInterval; // also a struct private ulong dm_MessageID; // System.Int64 type, ...

Is std::ifstream thread-safe & lock-free?

I intend to perform opening for reading a single file from many threads using std::ifstream. My concern is if std::ifstream is thread-safe & lock-free? More details: I use g++ 4.4 on Ubuntu & Windows XP, 4.0 on Leopard. Each thread creates its own instance of std::ifstream Thanks in advance! ...

Thread-safety of read-only memory access

I've implemented the Barnes-Hut gravity algorithm in C as follows: Build a tree of clustered stars. For each star, traverse the tree and apply the gravitational forces from each applicable node. Update the star velocities and positions. Stage 2 is the most expensive stage, and so is implemented in parallel by dividing the set of star...

Boost BGL thread safety

Hi! I'd like multiple threads to use the dijkstra_shortest_paths and astar_search functions of the BGL, and then read the property maps of the result vertices and edges. I'm wondering wether I should use mutexes to ensure thread-safety. So here are my questions: 1., Are the dijkstra_shortest_paths and astar_search functions of the Bo...

.NET Controls: Why aren't all calls thread-safe?

After exploding with excitement over learning about how to make thread-safe calls to Windows Form Controls, it got me thinking... Why aren't all calls to Windows Form Controls thread-safe? Can anyone explain why? I would think it would reduce a lot of confusion for users of those controls. ...

Thread safety in C# arrays

Does having 2 different threads : one reading from a C# array (e.g from first location), and another one writing to the same C# array but to a different location(e.g to the last location) is thread safe or not? (And I mean here without locking reading nor writing) ...

What exactly is a reentrant function?

Most of the times, the definition of reentrance is quoted from Wikipedia: A computer program or routine is described as reentrant if it can be safely called again before its previous invocation has been completed (i.e it can be safely executed concurrently). To be reentrant, a computer program or routine: Must hol...

Difference between Locks, Mutex and Critical Sections

There is an existing question regarding difference between Mutex and Critical section but it does not deal with Locks also. So i want to know whether Critical sections can be used for thread synchronisation between processes. Also what is meant by signalled states and non-signalled states ...

If a method does not use object's fields then it is thread safe?

If a public method of an object only uses parameters passed, and local variables, then can we say that it is thread-safe? ...

Thread Safety of C# List<T> for readers

I am planning to create the list once in a static constructor and then have multiple instances of that class read it (and enumerate through it) concurrently without doing any locking. In this article http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx MS describes the issue of thread safety as follows: Public static (Shared in Vi...

Can the lock function be used to implement thread-safe enumeration?

I'm working on a thread-safe collection that uses Dictionary as a backing store. In C# you can do the following: private IEnumerable<KeyValuePair<K, V>> Enumerate() { if (_synchronize) { lock (_locker) { foreach (var entry in _dict) yield return entry; } } else { foreach (var...

Thread safety with heap-allocated memory

I was reading this: http://en.wikipedia.org/wiki/Thread_safety Is the following function thread-safe? void foo(int y){ int * x = new int[50]; /*...do some stuff with the allocated memory...*/ delete [] x; } In the article it says that to be thread-safe you can only use variables from the stack. Really? Why? Wouldn't subse...