Skip to content

Poisoned Mutex at runtime with nightly #15851

Closed
@daschl

Description

@daschl

Hi folks,

I'm not sure if I messed up here, but since this looks suspicious at runtime and works sometime I thought I gotta raise it here.

The code is as follows:

use std::sync::{Arc, Mutex};

fn main() {
    let num_threads = 4;

    let vec_arc = Arc::new(Mutex::new(Vec::with_capacity(num_threads)));

    for i in range(0u, num_threads) {
        let mutex = vec_arc.clone();

        spawn(proc() {
            let mut vec = mutex.lock();
            vec.insert(i, i);
            println!("vec is now {}", *vec);
        })
    }
}

When I run it on the command line, most of the time it works correctly:

vec is now [0]
vec is now [0, 1]
vec is now [0, 1, 2]
vec is now [0, 1, 2, 3]

But sometimes this comes up:

task '<unnamed>' failed at 'assertion failed: index <= len', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcollections/vec.rs:1000
task '<unnamed>' failed at 'Poisoned Mutex - another task failed inside!', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsync/lock.rs:46
task '<unnamed>' failed at 'Poisoned Mutex - another task failed inside!', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsync/lock.rs:46
task '<unnamed>' failed at 'Poisoned Mutex - another task failed inside!', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsync/lock.rs:46

Is this expected to happen? I'm on rustc 0.12.0-pre-nightly (f15d6d2 2014-07-20 22:46:29 +0000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions