Skip to content

Mutex::try_lock doesn't error in wasm32-emscripten #156350

@curiousdannii

Description

@curiousdannii

Mutex::try_lock doesn't produce an Err in wasm32-emscripten.

use std::sync::Mutex;
fn main() {
    let m: Mutex<u32> = Mutex::new(1);
    let a = m.try_lock().unwrap();
    let b = m.try_lock().unwrap();
    println!("a + b = {}", *a + *b)
}

In x64, compiling and running this produces:

thread 'main' panicked at try_lock.rs:6:26:
called `Result::unwrap()` on an `Err` value: "WouldBlock"

When built with --target=wasm32-unknown-emscripten (default non-pthreads) there is no error:

a + b = 2

Discovered by @joelburton in curiousdannii/remglk-rs#11

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-emscriptenTarget: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL!T-libsRelevant to the library team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions