Having written a small amount of multi-threaded code, one of the hardest things to deal with is detecting where race conditions could occur. This is especially true in code you write, believing it is thread safe, only to find out later it isn't.

Are there any general tips for analyzing and writing code to determine where race conditions could occur?