Skip to content

Question about aliasing and thread safety #63

@Nugine

Description

@Nugine

SQ, CQ and Registrar contain NonNull<io_uring> which point to the same value.

pub struct SubmissionQueue<'ring> {
ring: NonNull<uring_sys::io_uring>,
_marker: PhantomData<&'ring mut IoUring>,
}

pub struct CompletionQueue<'ring> {
pub(crate) ring: NonNull<uring_sys::io_uring>,
_marker: PhantomData<&'ring mut IoUring>,
}

iou/src/registrar/mod.rs

Lines 47 to 50 in 045f8d4

pub struct Registrar<'ring> {
ring: NonNull<uring_sys::io_uring>,
_marker: PhantomData<&'ring mut IoUring>,
}

NonNull::as_ref and NonNull::as_mut require borrow check.

But if we split (SQ, CQ) into a producer thread and a consumer thread, both of them can access the same value without synchronization and break the borrow rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions