pub struct PreThreadAttestation { /* private fields */ }Expand description
Attests that the process is single-threaded at construction time.
UdsListener::bind calls umask(2), which is process-wide; any thread
creating filesystem objects during the bind window would inherit the
restricted umask. Holding a &PreThreadAttestation encodes the
single-threaded precondition in the type signature so the invariant is
enforced at compile time, not just by convention.
Construct exactly once at the top of fn main, before any thread spawn:
let pre_thread = PreThreadAttestation::new()?;
// … then pass &pre_thread to Observer::bind / UdsListener::bindThe token is !Send + !Sync (via PhantomData<*const ()>) so it cannot
be moved into or shared across thread boundaries after construction.
Implementations§
Source§impl PreThreadAttestation
impl PreThreadAttestation
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Probe the OS thread count and return a token if the process is single-threaded.
On Linux counts /proc/self/task/ entries. On macOS calls
pthread_is_threaded_np(3). On other platforms the runtime probe is
skipped; the type-level structural guarantee still holds.
§Errors
Returns io::ErrorKind::Other if the process has more than one
thread, or if the Linux /proc/self/task directory is unreadable.
Sourcepub unsafe fn new_unchecked() -> Self
pub unsafe fn new_unchecked() -> Self
Create a token without a runtime probe.
Intended for test code where the multi-threaded test runner would incorrectly fail the probe even though the umask window is benign.
§Safety
The caller must ensure that no concurrent thread creates filesystem
objects during the UdsListener::bind window, or that any such race
is acceptable in the calling context.