Skip to content

Break in v0.13->v0.14 #116

Closed
Closed

Description

@nbrr

Studying this piece of code from audio-visualizer, I extracted it in my play project as

pub fn setup_stream(config: &StreamConfig, device: &Device, buffer: Arc<Mutex<AllocRingBuffer<f32>>>) -> Stream {
    device
        .build_input_stream(
            config,
            move |data: &[f32], _info| {
                let mut audio_buffer = buffer.lock().unwrap();
                audio_buffer.extend(data.iter().copied());
            },
            move |error: StreamError| eprintln!("error on input audio stream: {}", error),
        None
        )
        .unwrap()
}

Build is successful with ringbuffer v0.13 but it fails with v0.14:

error[E0277]: `*mut f32` cannot be sent between threads safely
   --> src/lib.rs:24:13
    |
22  |           .build_input_stream(
    |            ------------------ required by a bound introduced by this call
23  |               config,
24  | /             move |data: &[f32], _info| {
25  | |                 let mut audio_buffer = buffer.lock().unwrap();
26  | |                 audio_buffer.extend(data.iter().copied());
27  | |             },
    | |_____________^ `*mut f32` cannot be sent between threads safely
    |
    = help: within `AllocRingBuffer<f32>`, the trait `Send` is not implemented for `*mut f32`
    = note: required because it appears within the type `AllocRingBuffer<f32>`
    = note: required for `Mutex<AllocRingBuffer<f32>>` to implement `Sync`
    = note: required for `Arc<Mutex<AllocRingBuffer<f32>>>` to implement `Send`
note: required because it's used within this closure
   --> src/lib.rs:24:13
    |
24  |             move |data: &[f32], _info| {
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `build_input_stream`
   --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cpal-0.15.2/src/traits.rs:134:46
    |
134 |         D: FnMut(&[T], &InputCallbackInfo) + Send + 'static,
    |                                              ^^^^ required by this bound in `DeviceTrait::build_input_stream`

There is no changelog or github tag to compare, but looking at the doc.rs pages for 0.13 and 0.14 what stands out is that it went from Send to !Send. Was that expected?

Activity

  1. added a commit that references this issue on Jun 18, 2023
    def2a2c
  2. jdonszelmann commented on Jun 18, 2023

    @jdonszelmann
    Collaborator

    You are correct, we switched up some code and did not sufficiently test this. #117 addresses this, by implementing Send and Sync explicitly (which is sound). I'm sorry for the inconvenience, and hope this change solves your problem.

  3. jdonszelmann commented on Jun 18, 2023

    @jdonszelmann
    Collaborator

    0.14.1 should fix this.

  4. added a commit that references this issue on Jul 11, 2025
    e19be53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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