Process-shared + robust mutex fails on riscv64, works on aarch64

Host environment

  • Operating system: Ubuntu
  • Architecture: x86
  • QEMU flavor: qemu-riscv64-static
  • QEMU version: qemu-riscv64 version 10.0.2 (Debian 1:10.0.2+ds-1)
  • QEMU command line: qemu-riscv64-static -L /usr/riscv64-linux-gnu/ test_mutex

Emulated/Virtualized environment

  • Operating system: debian trixie
  • Architecture: riscv64

Description of problem

When building and running the following code on riscv64, the combination of process-shared and robust mutex attributes fails with "Operation not supported". On aarch64, the same code works as expected.

Code

// test_mutex.c



#include <stdio.h> 
#include <pthread.h> 
#include <errno.h> 
#include <string.h>

int main() { 
    pthread_mutexattr_t attr;
    pthread_mutex_t mutex;

    pthread_mutexattr_init(&attr);
    pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
    pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);

    int ret = pthread_mutex_init(&mutex, &attr);
    if (ret != 0) {
       printf("pthread_mutex_init failed: %s\n", strerror(ret));
       return 1;
     }
     printf("Mutex initialized successfully.\\n"); return 0;
}

Steps to reproduce

  1. Compile for riscv: riscv64-linux-gnu-gcc test_mutex.c -lpthread -o test_mutex_riscv

  2. Run with qemu: qemu-riscv64-static -L /usr/riscv64-linux-gnu/ test_mutex_riscv

  3. Output: pthread_mutex_init failed: Operation not supported

  4. Compile for arm: aarch64-linux-gnu-gcc test_mutex.c -lpthread -o test_mutex_arm

  5. Run with qemu: qemu-aarch64-static -L /usr/aarch64-linux-gnu/ test_mutex_arm

  6. Output: Mutex initialized successfully.

Additional information

  • only the combination of robust and process_shared leads to the issue, using only one of both attributes ore none works fine.
Edited by Jonas Lassen