What are the usual difficulties in concurrent programming and tuning of concurrent programs (shared-memory model)

concurrency

I can list part of the problems that will show up when writing a moderately-sized concurrent application with shared memory:

  • Locking granularity
  • Choice of synchronization primitive
  • Number of threads
  • Method for decomposing into threads (data parallelism; task parallelism; how threads are organized, etc)

What are other similar problems?

Best Answer

The two most common problems in my experience of taking a class on the subject were the debugging of programs and the efficient distribution of resources.

Debugging a parallel program particularly on an independently managed thread system is astonishingly difficult. It's non-deterministic which means that your program may work 999 times out of a 1000 and that one time it fails just because something arrived in the wrong order or the thread manager didn't allocate correctly.

Atomicity errors are also common, this is why functional languages are becoming popular to handle concurrency as they wall off state (it's not that they don't have a state, it's that it's transparent).

The other big issue is communication. This falls into two categories: Resourcing and Time. Resourcing refers to often limited cache sizes and memory allocations for individual processes. Parallel systems often see use in data heavy applications, thus proper flow and packaging of that data is important. There's also the issue of dealing with the fact that there may not be a good algorithm that efficiently does what you want. Some tasks aren't not easily parallelizable and even if they are, the communication involved may render any speed gains moot. Time refers to the communication times between processors. This is less an issue in "multicore" systems than in distributed ones but it's still a problem.

You might ask why I'm talking about distributed systems at all. Well, some "shared memory" systems are actually distributed with particular facilities that make them function as shared memory.

Related Topic