This code is thread safe... as all writes and reads to and from primitive types like bools are atomic. Although, you do have two checks on the
isEnd
bool happening here... in the while declaration, and in the body of the while statement.
There are other issues that can crop up concerning compiler optimizations, and possibly optimizing your code in a way that renders any changes to the
isEnd
boolean invisible to the checking thread.
Take a look at the volatile keyword in C# for more information on compiler optimization, and how to avoid it on specific variables.
http://msdn.microsoft.com/en-us/library/x13ttww7(v=vs.110).aspx[
^]