Why is programming threads hard?

I keep reading stuff about most engineers being too stupid to understand how to program threads. I don’t get it.

I never used threads until I started programming in Java 10+ years ago and it seemed pretty easy. You create a new thread, let it do some stuff and join() on it if you want to wait for it to complete. It makes it easy to access things in memory across threads. Of course if you want to modify things in that shared memory, you have to implement some locking on those objects, but that’s not that hard either. Perhaps it’s a bit harder if you’re programming threads in a language that doesn’t manage memory.

So tell me, am I a programming genius that finds threads easy (unlikely) or am I missing some big usage of threads that makes it impossible for a mental peon like me (more likely)?

2 Comments

  1. Java does make it very easy–that’s not the case with most programming languages. This gives multi-threaded applications a bad reputation…

    Furthermore, the actual difficulty lies in designing reentrant functions that lock as little as possible, but guarantee the consistency of their data. Although data consistency guarantees are easy to make, locking as little as possible can be a problem. Avoiding deadlock is even harder in complicated designs.

    Here’s an example of an obscure deadlock condition in a Java implementation of JSON: http://sourceforge.net/tracker/?func=detail&atid=857928&aid=2817570&group_id=171425

Leave a Reply

Your email address will not be published. Required fields are marked *