The regular "Thread Safety" section of the MSDN documentation for StringBuilder
states that:
...any instance members are not guaranteed to be thread safe...
but this statement feels like it has been copied and pasted for almost every class in the Framework:
http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx
However, these blog posts by Gavin Pugh mention thread-safe behaviours of StringBuilder
:
http://www.gavpugh.com/2010/03/23/xnac-stringbuilder-to-string-with-no-garbage/
http://www.gavpugh.com/2010/04/01/xnac-avoiding-garbage-when-working-with-stringbuilder/
Additionally, the source of StringBuilder revealed by Reflector, and the accompanying comments in the SSCLI source, also suggest many implementation considerations to ensure thread-safety:
Does anyone have any more insight into whether a StringBuilder
instance is safe to share among multiple concurrent threads?