concurrency

How does the Reactive Framework (Rx) relate to Tasks in .NET 4?

Asynchronous and concurrent programmings seams to be on everyones minds these days and .NET 4 adds a number of improvements such as built-in thread safe collections and of course tasks. On top of this I've started looking at the Reactive Framework (Rx). Tasks appears to be primarily more focused on concurrency for computation performanc...

How should I measure Concurrent Licence Usage

Hi I have detailed stats on user access to my system detailing login and logout times as well as machine used, network username etc. I am in need of measuring what I would term a concurrent user licences level based on this information. Now I could take the maximum logged in for any 1 day in a 3 month period say 170 or I could take the...

Synchronize on BlockedQueue.

Hello, I have a code piece that I am reviewing (using FindBug). public class MyClass{ ... private BlockedQueue q = new LinkedBlockingQueue<MyData>(1000); private static final batchSize = 1000; public boolean testMethod(){ boolean done = false; synchronized(q){ if(q.size == batchSize){ q.notify(); done...

Can you lock on a local object in Java?

I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t = xlCache.get(name); synchronized(t){ if (!t.isValid()) { xlCache.remove(name); return null; } } return t.getTemplate(); } xlCache is a Concurrent...

Future Protections in Managed Languages and Runtimes

In the future, will managed runtimes provide additional protections against subtle data corruption issues? Managed runtimes such as Java and the .NET CLR reduce or eliminate the possibility of many memory corruption bugs common in native languages like C#. Nonetheless, they are surprisingly not immune from all memory corruption problems...

changed object state after behavior that used the state

I want to give my previous question a second chance since I think I have chosen a bad example. The question is how I should deal with situations where an object still can change after I have used it to do something and the new state is relevant for what is being done. Example in pseudo-code: class Book method 'addChapter': adds a ...

Is this the right approach for a thread-safe Queue class?

Hey guys, I'm wondering if this is the right approach to writing a thread-safe queue in C++? template <class T> class Queue { public: Queue() {} void Push(T& a) { m_mutex.lock(); m_q.push_back(a); m_mutex.unlock(); } T& Pop() { m_mutex.lock(); T& temp = m_q.pop(); m_mutex.unlock(); return temp; } private...

Why are closures suddenly useful for optimizing programs to run on multiple cores?

I read an article that claims that closures (or "blocks") are a useful weapon in the "War on Multicores", because [...] they allow you to create units of work, which each have their own copy of the stack, and don’t step on each others toes as a result. What’s more, you can pass these units around like they are values, when ...

Why don't I see pipe operators in most high-level languages?

In Unix shell programming the pipe operator is an extremely powerful tool. With a small set of core utilities, a systems language (like C) and a scripting language (like Python) you can construct extremely compact and powerful shell scripts, that are automatically parallelized by the operating system. Obviously this is a very powerful ...

Strategies to issue unique records via db?

Hi, We have more than 1 instances of a certain exe running from different locations. An exe is supposed to fetch a set of records and do some work based on them. The set of records fetched from exe A should not be fetched by exe B and vice versa. Exes A & B are the same exes; they are running from different locations. The number of inst...

java.util.ConcurrentModificationException on CollectionOfElements

Hi. I seem to get a ConcurrentModificationException when I have a CollectionOfElements inside an Embedabble. If would like to have it like that, however If I change Route from Embedabble's to Entity than everything works fine. I have even tried adding @Version, but that doesn't seem to work. Here are a snippet of my classes. Kart.java:...

NSCFArray mutated while being enumerated - but I don't use enumerators

One thing I really don't like about Objective-C is that it's very difficult to find out what's going on under the hood. The latest problem this has caused me is a random exception that occurs in random places in my code and breaks everything - it's the one listed above, about concurrency problems with NSArray. The thing is that I never...

Does a StreamReader lock a text file whilst it is in use? Can I prevent this?

Does a StreamReader lock a text file whilst it is reading it? If it does, can I force the StreamReader to work in a "read-only" or "non locking" mode? My workaround would be to copy the file to a temp location and read it from there but I would prefer to use the StreamReader directly if possible. Any alternative suggetions? Background:...

Does this stack dump indicate that I have a deadlock ?

I have a REST service built using Jersey. When I performed a "curl" against my REST API, the command hangs. I ran jstack & this is a summarized output of two threads in BLOCKED state. "pool-2-thread-11" prio=6 tid=0x01d51800 nid=0x2394 waiting for monitor entry [0x05e6f000..0x05e6fce8] java.lang.Thread.State: BLOCKED (on object moni...

Concurrency issues in Spring DAOs with 3.0.0.RC1

Hi guys, After upgrading from Spring 3.0.0.M4 to 3.0.0.RC1 and Spring Security 3.0.0.M2 to 3.0.0.RC1, I've had to use a security:authentication-manager tag instead of defining an _authenticationManager like I used to in M4/M2. I've done my best at defining it, and ended up with this: <security:authentication-manager alias="authenticati...

Android: One vs many instances of HttpClient per application

Until recently, our app shared a single Apache HttpClient instance using the ThreadSafeClientConnManager across the whole application. The http client instance was held by a singleton class. Since I dislike the singleton pattern for its numerous problems, I refactored our API accessor to be a per-thread object, but now for every thread ...

Do sequence points prevent code reordering across critical section boundaries?

Suppose that one has some lock based code like the following where mutexes are used to guard against inappropriate concurrent read and write mutex.get() ; // get a lock. T localVar = pSharedMem->v ; // read something pSharedMem->w = blah ; // write something. pSharedMem->z++ ; // read and write something. mutex.release() ; // rel...

What is the best Clustering or Distributed System solution for Java applications

What are the best approaches to clustering/distributing a Java server application ? I'm looking for an approach that allows you to scale horizontally by adding more application servers, and more database servers. What technologies (software engineering techniques or specific technologies) would you suggest to approach this type of pro...

AsyncTask and Android threading: how to get it right ?

I am firing off an AsyncTask to fetch images via HttpClient. Via DDMS in eclipse, the view shows that the AsyncTask runs and then hangs around. This is a screenshot of the DDMS threads view. Should the AsyncTask #1 thread disappear or is it benign ? What does the status wait mean anyway ? ...

Not thread safe Object publishing

Reading Java concurrency in practice, section 3.5: Claim is raised that public Holder holder; public void initialize() { holder = new Holder(42); } Besides the obvious thread safely hazard of creating 2 instances of Holder the book claims a possible publishing issue can occur, further more for a Holder class such as public Hold...