Skip to content

Segmentation fault when calling set_thread_priority_and_policy #41

@mmasque

Description

@mmasque

The following example code yields a segmentation fault on an aarch64 Linux machine. I confirmed that the segfault occurs on the unsafe execution of libc::pthread_setschedparam.
The code succeeds on an x86 machine.

Note also that set_thread_priority_and_policy has varying requirements for its ThreadId, which depend on the type of policy passed: for setting deadline on the current thread, 0 should be used as the id, while thread_native_id() should be used when setting a thread to the deadline policy. This should be documented or changed to avoid confusion, in my opinion.

use thread_priority::*;
fn main() {
    // Succeeds
    assert!(set_thread_priority_and_policy(
        thread_native_id(),
        ThreadPriority::Min,
        ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::Fifo),
    )
    .is_ok());
    // Segmentation fault on aarch64, succeeds on x86
    assert!(set_thread_priority_and_policy(
        0,
        ThreadPriority::Min,
        ThreadSchedulePolicy::Realtime(RealtimeThreadSchedulePolicy::Fifo),
    )
    .is_err());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions