[BUG] Rust: libc::PTHREAD_MUTEX_INITIALIZER is incorrect

Đang mở
#20,407 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Sôi nổi
Công nghệ
c, rust

Hướng nghiên cứu

Compare Rust libc's definition in src/unix/nuttx/mod.rs with NuttX's PTHREAD_MUTEX_INITIALIZER in include/pthread.h and NXSEM_NO_MHOLDER in include/nuttx/semaphore.h. Then inspect Rust std's use in library/std/src/sys/pal/unix/sync/mutex.rs. Done means an agreed approach produces a valid mutex initializer across the relevant NuttX configurations.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Arch: all Area: Applications Area: Posix OS: BSD OS: Linux OS: Mac OS: Windows Type: Bug
Description / Steps to reproduce the issue

Rust libc initializes PTHREAD_MUTEX_INITIALIZER to 0: https://github.com/rust-lang/libc/blob/c2744242b816317ea8b5c8e306eb829c080cb2b9/src/unix/nuttx/mod.rs#L310

But in NuttX this is generally not 0.
For example, defined here: https://github.com/apache/nuttx/blob/master/include/pthread.h#L359
Going into https://github.com/apache/nuttx/blob/master/include/pthread.h#L353
Which makes use of NXSEM_NO_MHOLDER, defined here: https://github.com/apache/nuttx/blob/master/include/nuttx/semaphore.h#L70
Furthermore, the initialization also depends on the configuration.

In Rust, std makes use of the constant to init mutexes, e.g. here: https://github.com/rust-lang/rust/blob/7d2cd0fbc092625ea371da704f15f80216d2220e/library/std/src/sys/pal/unix/sync/mutex.rs#L12

I'm not sure what the best solution is, I see some options:

  • remove the symbol definition from Rust (and update std to use pthread_mutex_init instead)
  • init the Rust definition to a matching value and either require a certain config or make sure the position of the non-zero values is independent from the config
  • update NuttX so the definition is always 0 (in addition to requiring a specific config)
On which OS does this issue occur?

[OS: Linux], [OS: BSD], [OS: Mac], [OS: Windows]

What is the version of your OS?

Irrelevant

NuttX Version

master

Issue Architecture

[Arch: all]

Issue Area

[Area: Posix], [Area: Applications]

Host information

No response

Verification
  • I have verified before submitting the report.
Ngôn ngữ chính
C
Star
4.1k
Fork
1.8k
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
841

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/nuttx

Tất cả issue của apache/nuttx

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.