concurrency

Why doesn't more Java code use PipedInputStream / PipedOutputStream ?

I've "discovered" this idiom recently, and I am wondering if there is something I am missing. I've never seen it used. Nearly all Java code I've worked with "in the wild" favors slurping data into a string or buffer, rather than something like this example (using HttpClient and XML APIs for example): final LSOutput output; // XML st...

.NET Dictionary: Potential concurrency problems?

Hi all. I'm working on maintenance of a .NET project, and I'm having some troubles which I'll gladly share with you guys =) The problem code: if( evilDict.Count < 1 ) { foreach (Item item in GetAnotherDict()) if (!evilDict.containsKey(item.name.ToLower().Trim())) evilDict.add(item.name.ToLower().Trim(), item.ID)...

Which lock hints should I use (T-SQL)?

I want to implement an atomic transaction like the following: BEGIN TRAN A SELECT id FROM Inventory WITH (???) WHERE material_id = 25 AND quantity > 10 /* Process some things using the inventory record and eventually write some updates that are dependent on the fact that that specific inventory record had sufficient quantity (greater ...

LINQ to SQL - Update to increment a non-primary-key field - thread-safe

I have two tables (well, two relevant for this question) : Bets (holds the bets; Columns : Id, , MessagesPosted, ) Bets_Messages (holds the bets' forum messages; Columns : Id, BetId, ) When I insert a new BetMessage in Bets_Messages I want to update (increment to be precise) the corresponding field in Bets. In pure T-SQL that would be...

[F#] Mailbox Processor on Distributed Systems

I noticed the following comment in my copy of Expert F# on page 379: Passing and Processing Messages A distinction is often made between shared-memory concurrency and message passing concurrency. The former is often more efficient on local machines and is covered in the section "Using Shared-Memory Concurrency" later i...

Does it make sense to spawn more than one thread per processor?

From a logical point of view an application may need dozens or hundreds of threads, some of which will we sleeping most of the time, but a very few will be always running concurrently. The question is: Does it make any sense to spawn more concurrent threads than processors there are in a system, or it is a waste? I've seen some server a...

Java concurrency cynicism gone too far?

I was wondering if some of you who are experienced in concurrency programming could help me interpret a statement/philosophy properly. I have a copy of Bruce Eckel's grand tome Thinking In Java (4th ed) which has some fairly good coverage of a number of areas of Java which are kind of difficult for beginners to get into. I really enjoye...

How do I stop the DateTimeOffset scale from causing a ChangeConflictException in linq to Sql?

The following code tries to create a new record and then modify it after it has been committed to the database. The last SubmitChanges() call throws a ChangeConflictException. ItemA itemA = new ItemA(); itemA.Foo = "a"; itemA.Created = DateTimeOffset.Now.UtcDateTime; ItemAs.InsertOnSubmit(itemA); SubmitChanges(); itemA.Foo = "b"; Subm...

What's the difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?

I have a Map which is to be modified by several threads concurrently. There seem to be three different synchronized Map implementations in the Java API: Hashtable Collections.synchronizedMap(Map) ConcurrentHashMap From what I understand, Hashtable is an old implementation (extending the obsolete Dictionary class), which has been ad...

.Net Static Methods and it's effects on Concurrency ?

I am currently building an API which will be used by a webservice. I was wondering what performance issues I could meet if I built my API using a large amount of static methods. The original idea was to build expert objects which act as services. In a single user environment this approach was great! But I will soon need to port this...

Are Concurrent SQL inserts into the same table transactionally safe ?

I have a simple table in MySql whose raison-d'être is to store logs. The table has an autoincremented sequence and all the other columns has zero referential integrity to other tables. There are no unique keys or indexes on any columns. The column with autoincrement is the primary key. Will concurrent INSERTs ever interfere with each ot...

Unexpected multithreaded result

I wrote a couple of Java classesSingleThreadedCompute and MultithreadedComputeto demonstrate the fact (or what I always thought was a fact!) that if you parallelize a compute-centric (no I/O) task on a single core machine, you don't get a speedup. Indeed my understanding is that parallelizing such tasks actually slows things down because...

Classic database insert problem

I have a SQL database which i use to store some info and every record has a unique id generated by the database. MY program is written in flash and runs over the web, the program runs fine and it inserts records into the database and pulls the idnumber of the last record and displays it for user, my question is though how do i handle mul...

What are common concurrency pitfalls?

I'm looking into educating our team on concurrency. What are the most common pitfalls developers fall into surrounding concurrency. For instance, in .Net the keyword static opens the door to a lot of concurrency issues. Are there other design patterns that are not thread safe? Update There are so many great answers here it is difficul...

Is it a good way to use java.util.concurrent.FutureTask ?

First of all, I must say that I am quite new to the API java.util.concurrent, so maybe what I am doing is completely wrong. What do I want to do? I have a Java application that basically runs 2 separate processing (called myFirstProcess, mySecondProcess), but these processing must be run at the same time. So, I tried to do that: publ...

Problem with thread-safe queue?

I'm trying to write a thread-safe queue using pthreads in c++. My program works 93% of the time. The other 7% of the time it other spits out garbage, OR seems to fall asleep. I'm wondering if there is some flaw in my queue where a context-switch would break it? // thread-safe queue // inspired by http://msmvps.com/blogs/vandooren/archiv...

How does .NET make use of IO Threads or IO Completion Ports?

We have a .NET application that makes several concurrent calls to various web services, collects their responses and then makes a few calculations off those responses. In attempting to derive additional performance, I've been investigating the use of approaches that make use of .NET's IO threading via the use of IO completion ports. I've...

Book or Resource on C# Concurrency

I have heard many good things about the book Java Concurrency in Practice. Is there a good equivalent book for C#? ...

What problem characteristics promote the use of parallel/concurrent architectures?

I am quite excited by the possibility of using languages which have parallelism / concurrency built in, such as stackless python and erlang, and have a firm belief that we'll all have to move in that direction before too long - or will want to because it will be a good/easy way to get to scalability and performance. However, I am so u...

Using thread.join to make sure all threads in a collection execute before moving on

Is there a problem with this type of implementation to wait for a batch of threads to complete before moving on, given the following circumstances?: CCR or PFX cannot be used. Customer.Prices collection and newCustomer are NOT being mutated. CloneCustomerPrices performs a deep copy on each of the prices in Customer.Prices collection in...