-1

from the doc:

BytesMut represents a unique view into a potentially shared memory region. Given the uniqueness guarantee, owners of BytesMut handles are able to mutate the memory.

BytesMut can be thought of as containing a buf: Arc<Vec>, an offset into buf, a slice length, and a guarantee that no other BytesMut for the same buf overlaps with its slice. That guarantee means that a write lock is not required.

  1. why multiple owners of BytesMut can mutate the memory concurrently?
  2. why a write lock is not required?
  3. how is it implemented?
linuxfish
  • 89
  • 1
  • 8

1 Answers1

2

why multiple owners of BytesMut can mutate the memory concurrently? why a write lock is not required?

From the docs: and a guarantee that no other BytesMut for the same buf overlaps with its slice.

There is no overlap, so it is safe to mutate it since no one else can mutate that region. Also no lock need for the same reason, no synchronization is needed since there is no overlap.

how is it implemented?

You can take a look at the source code

Netwave
  • 40,134
  • 6
  • 50
  • 93