memcpy() safety on adjacent memory regions

Posted by JaredC on Stack Overflow See other posts from Stack Overflow or by JaredC
Published on 2011-01-14T19:45:30Z Indexed on 2011/01/14 21:54 UTC
Read the original article Hit count: 162

Filed under:
|
|

I recently asked a question on using volatile and was directed to read some very informative articles from Intel and others discussing memory barriers and their uses. After reading these articles I have become quite paranoid though.

I have a 64-bit machine. Is it safe to memcpy into adjacent, non-overlapping regions of memory from multiple threads? For example, say I have a buffer:

char buff[10];

Is it always safe for one thread to memcpy into the first 5 bytes while a second thread copies into the last 5 bytes?

My gut reaction (and some simple tests) indicate that this is completely safe, but I have been unable to find documentation anywhere that can completely convince me.

© Stack Overflow or respective owner

Related posts about c++

Related posts about multithreading