concurrency

Functional programming: immutability etc.

I recently asked a question about functional programming, and received (good!) answers that prompted more questions (as seems to be the case with learning, sometimes). Here are a couple examples: One answer made reference to an advantage of immutable data structures: each thread can have its own copy. Now, to me, this sounds rather lik...

Java memory model - can someone explain it?

For years and years, I've tried to understand the part of Java specification that deals with memory model and concurrency. I have to admit that I've failed miserably. Yes' I understand about locks and "synchronized" and wait() and notify(). And I can use them just fine, thank you. I even have a vague idea about what "volatile" does. But ...

How are you taking advantage of Multicore?

As someone in the world of HPC who came from the world of enterprise web development, I'm always curious to see how developers back in the "real world" are taking advantage of parallel computing. This is much more relevant now that all chips are going multicore, and it'll be even more relevant when there are thousands of cores on a chip...

Changing async call implementation using a ManualResetEvent to one using a combination of Thread methods

I'm looking for a design pattern to switch from using a ManualResetEvent to using Thread methods like Thread.Join. Right now I'm making an async call and then using a ManualResetEvent to wait till the async call finishes before continuing on the thread that made the call. I'd be glad for any implementation that would produce more stable...

Is it possible for two ExecutorServices to share a thread pool?

I've got a collection of records to process, and the processing can be parallelized, so I've created an ExecutorService (via Executors#newCachedThreadPool())). The processing of an individual record is, itself, composed of parallelizable steps, so I'd like to use another ExecutorService. Is there an easy way to make this new one use the ...

Oracle function concurrency

I currently have an INSERT TRIGGER which in Oracle 10g runs a custom defined function that generates a funky alpha-numeric code that is used as part of the insert. I really need to make sure that the function (or even trigger) is thread safe so that if two users activate the trigger at once, the function used within the trigger does NOT...

Which concurrent programming concepts do hiring managers expect developers to understand?

When I hire developers for general mid-to-senior web app development positions, I generally expect them to understand core concurrent programming concepts such as liveness vs. safety, race conditions, thread synchronization and deadlocks. I'm not sure whether to consider topics like fork/join, wait/notify, lock ordering, memory model bas...

Stackless python and multicores?

So, I'm toying around with Stackless Python and a question popped up in my head, maybe this is "assumed" or "common" knowledge, but I couldn't find it actually written anywhere on the stackless site. Does Stackless Python take advantage of multicore CPUs? In normal Python you have the GIL being constantly present and to make (true) use ...

Using entity framework, should I add a timestamp to all my database tables?

I'm planning to use MS entity framework for new web apps (come on EF v2!). So does it make sense to plan ahead by adding timestamp columns to all entity tables in existing and future databases, to support concurrency checks? Is there any reason why it would be a bad idea to have a timestamp column in every table? Note that the point is...

How can threads be avoided?

I've read a lot recently about how writing multi-threaded apps is a huge pain in the neck, and have learned enough about the topic to understand, at least at some level, why it is so. I've read that using functional programming techniques can help alleviate some of this pain, but I've never seen a simple example of functional code tha...

What's the best way to unit test concurrent Erlang code?

I'm spending a bit of time with Erlang, and I'm wanting to apply TDD to code I'm writing. While EUnit in the standard lib provides a nice traditional unit testing framework for testing regular style code, there doesn't seem to be anything to help specifically with testing concurrent code, which is used a LOT in Erlang. Note that we're ...

What are some interesting projects to solve in Erlang for learning purposes?

I recently discovered Erlang and am now working my way through a couple of tutorials. By now I'm looking forward to actually implement something as a hobby project. I'm not really interested in yet another chat server. I would like to code something more interesting (yes I'm aware that this is a rather fuzzy term) which is also manageabl...

PHP calling multiple videos to convert at once via mencoder.How can I limit it?

Hello all, I am new here. I recently installed my video script to a new server but I am seeing that it will start to convert 1 video (via mencoder) then before finishing it, it will try and convery another, and another, so it will be trying to convert 4+ videos at the same time causing the server to shut down. The script developer said:...

Detecting that a ThreadPool WorkItem has completed/waiting for completion

For whatever reason, ThreadPool's QueueWorkItem doesn't return an IAsyncResult or some other handle to the work item, which would allow to wait until it's completed. There are RegisterWait... methods, but you have to pass a WaitHandle and creating them is expensive (see IAsyncResult documentation, which advises you to delay creating a Wa...

Implementing IAsyncResult explicitly

I am generally wary of implementing interfaces partially. However, IAsyncResult is a bit of a special case, given that it supports several quite different usage patterns. How often do you use/see used the AsyncState/AsyncCallback pattern, as opposed to just calling EndInvoke, using AsyncWaitHandle, or polling IsCompleted (yuck)? Related...

Using BeginInvoke/EndInvoke in a multithreaded fashion. How do AsyncCallback, AsyncWaitHandle and IsCompleted interact?

Andreas Huber's answer to this question gave me an idea to implement Concurrent<T> with async delegates instead of the ThreadPool. However, I am finding it harder to understand what's going on when an AsyncCallback is passed to BeginInvoke, especially when several threads have access to IAsyncResult. Unfortunately, this case doesn't seem...

Change Tracking Structure

We are looking to implement Optimistic locking in our WCF/WPF application. So far the best way I've come up with doing this is to implement a generic Optimistic which will store a copy of the original and any changes (so it will store two copies: the original and modified) of any value object that can be modified. Is this the best way of...

How to do text full history in Django?

I'd like to have the full history of a large text field edited by users, stored using Django. I've seen the projects: Django Full History (Google Code) Django ModelHistory, and Django FullHistory I've a special use-case that probably falls outside the scope of what these projects provide. Further, I'm wary of how well documented, te...

How do I know if a C# method is thread safe?

I'm working on creating a call back function for an ASP.NET cache item removal event. The documentation says I should call a method on an object or calls I know will exist (will be in scope), such as a static method, but it said I need to ensure the static is thread safe. Part 1: What are some examples of things I could do to make it u...

How to safely update a file that has many readers and one writer?

I have a set of files. The set of files is read-only off a NTFS share, thus can have many readers. Each file is updated occasionally by one writer that has write access. How do I ensure that: If the write fails, that the previous file is still readable Readers cannot hold up the single writer I am using Java and my current solution...