Terminology for Mutex data

This pattern comes up very often for me:

struct Inner {
  // .. read/write data ..
}

struct Shared {
  inner: Mutex<Inner>,
  signal: Condvar,
  // .. other shared read-only data ..
}

#[derive(Clone)]
struct Thing {
  sh: Arc<Shared>
}

Inner, in Rust, is often used when the public struct is merely a wrapper around the actual (inner) implementation, so I'm looking for a better term. Is there some (more or less) well-established term in the ecosystem for this specific use-case.

There are:

  • wrapper type: any sort of wrapper around another type, for the purpose of hiding or modifying the inner type's characteristics
  • newtype: a thin/transparent wrapper that has a different interface (API) for the wrapper type than the interface of the inner type, but has the same representation and size as the inner type
  • type with interior mutability: a wrapper around a cell of some kind (e.g., UnsafeCell, RefCell, Cell) that allows mutation, even via a shared reference (&) to the outer type

A Mutex is the third type.

No doubt there are others. So I don't think there is one answer. The fact that the term "inner" is used doesn't tell you which kind of wrapper it is, since it is just a convenient name for a wrapped object.

In Tokio we use the same names of Shared and Inner for these structs. When we call them something else, it's generally because there's some name that makes sense in that specific case only. For example:

3 Likes

I have used MutableFoo for the Mutex protected content of Foo before, but you might find you want to split your Mutexed data for some reason already (eg the read and write ends of a buffer, or the metadata and cache for a collection), which is a much more helpful name.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.