I teach concurrency a lot to my friends and co-workers. Here are some of the big pitfalls:
- Assuming that a variable that is mostly read in many threads and only written in one thread doesn't need to be locked. (In Java, this situation may result in the reading threads never seeing the new value.)
- Assuming that the threads will run in a particular order.
- Assuming that the threads will run simultaneously.
- Assuming that the threads will NOT run simultaneously.
- Assuming that all of the threads will make forward progress before any one of the threads ends.
I also see:
- Big confusions between
thread_fork() and fork().
- Confusions when memory is allocated in one thread and
free()d in another thread.
- Confusions resulting from the fact that some libraries are threadsafe and some are not.
- People using spin-locks when they should use sleep & awake, or select, or whatever blocking mechanism your language supports.