Skip to content

[BUG] barrier cause double free #432

@luansh

Description

@luansh

It run on 0.4.4

import "std/sync.zc"
import "std/thread.zc"
import "std/vec.zc"

def COUNT = 4;

fn worker(b: Barrier, delay: int) {
println "Before Sleep";
sleep_ms(delay);
b.wait();
println "After Sleep";
}

fn main() {
let ts = Vec::new();
let barrier = Barrier::new(COUNT);

for it in 0..COUNT {
ts.push(Thread::spawn(fn() { worker(barrier, it * 1000); }).unwrap());
}

for t in ts {
t.join();
}

sleep_ms(1000);
}

Terminal Output
Before Sleep
Before Sleep
Before Sleep
Before Sleep
After Sleep
After Sleep
After Sleep
double free or corruption (!prev)

It seems the last call to wait() cause the problem, and the last "After Sleep" can not be run

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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