Atomic Memory Operations

Hello.
How can I do atomic memcpy and memset operations in x64?
I can't use Interlocked* because the number of bytes I want to do an atomic operation on exceeds 64 bytes.
Any ideas?

Atomic in what sense? If you have a data structure accessed in multiple places that you do not want to leave in an inconsistent state, then you must do your own interlocking, using a spin lock or a critical section.

1 Like

Generally, when people say 'atomic' or 'lock free' what they mean is that the memory access is guarded by a hardware level lock.

obviously, this is only useful when a block of memory is accessed my multiple threads (CPUs) concurrently. In the old days, this used to be implemented via bus lock. For the last couple of decades, it has been implemented via coherency protocol. Memory fences allow single interlocked operations to protect other memory access etc. This is a complex topic

If the available hardware privatives are too small to handle the size of memory block you need to work on, then you have no choice except to use a software level lock. All software level locks are built on top of the hardware level ones.

If you are worried about performance, don't discount the effectiveness of the memory coherency protocols for memory accesses that don't conflict. And transactional memory solutions can be even better. Sometimes a lot better.

But there is far too much to say on this topic for a single post, so if you want better help, a more specific question would help you to get it faster