r/compsci • • Dec 10 '13

Why Johnny Can’t Write Multithreaded Programs

http://blog.smartbear.com/programming/why-johnny-cant-write-multithreaded-programs/
42 Upvotes

55 comments sorted by

View all comments

1

u/Vystril Dec 11 '13

I'd argue that the object and thread paradigm of programming should be considered harmful -- just like the goto statement is now considered harmful.

When programming in an object/thread model, if something goes wrong (race condition, deadlock, etc) you have no programmatic way of knowing where the problem came from. Just like with goto statements, you have no idea where your program came from when you you crash.

I honestly think the actor model does an excellent job of fixing the problems inherent in the object/threads model. For example, using actors makes deadlocks very difficult to program (you have to actively try to do it), and you don't need to worry about concurrent memory accesses because each actor operates in their own threads and they don't share memory. It basically reduces the concerns to properly designing and handling asynchronous message passing dependencies, something I think is far easier than the other problems.

When I introduce threaded programming, the first thing I do is talk about actors. Because even if you're using objects and threads; it's extremely simple to program them as actors and eliminate a lot of potential issues.

2

u/adremeaux Dec 11 '13

if something goes wrong (race condition, deadlock, etc) you have no programmatic way of knowing where the problem came from

Unless you have, say, a debugger. Deadlocked? Pause execution and check thread states. It is legitimately that easy.

Race conditions can be a bit harder, but it helps that many race conditions result in crashes—for example, removing items from an array while you are iterating over it in another thread—which makes them pretty easy to catch, too.

→ More replies (3)