简体   繁体   中英

C# and .NET: is Buffer.BlockCopy thread-safe for structs?

Basically the question is in the title. If I have an array of structs, will Buffer.BlockCopy behave properly in multithreaded environment? In other words, what will happen if during execution of Buffer.BlockCopy some thread tries to update a field on one of the stored structs? http://msdn.microsoft.com/en-us/library/teyhh36d.aspx documentation says static methods of Buffer (BlockCopy is static) are guaranteed to be thread-safe for simple types. But if my struct contains only simple types, can this guarantee stretch a little bit into my favor?

Buffer.BlockCopy is not an atomic operation on it's own. There's nothing stopping any other threads from either modifying fields of items in the array the array itself while the BlockCopy is being performed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM