Race Condition in Async/Await Code
问题 I just wonder whether a race condition occurs in the code below: int readingFiles; async Task<string> ReadFile (string file) { ++readingFiles; var text = await Stream.ReadFileAsync(file); --readingFiles; return text; } If ReadFile method is executed by a thread pool thread, readingFiles will be accessed by two different threads and the readingFiles variable is not protected by any synchronization idioms. It means that the first update to readingFiles should not be visible to the other thread