Skip to content

windows-threading lifetime soundness issue #3695

@adedomin

Description

@adedomin

Summary

After looking into #3694, I was confused how the windows_threading::Pool example worked vs (scoped) threads without unsafe. I suspected there may be a lifetime bug in pool.submit and i was able to get a segfault when executing an example.

PS C:\Users\prussian\source\example-winthread> cargo run
   Compiling example-winsvc v0.1.0 (C:\Users\prussian\source\example-winthread)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.24s
     Running `target\debug\example-winthread.exe`
error: process didn't exit successfully: `target\debug\example-winthread.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

see example code below.

Crate manifest

[package]
name = "example-winthread"
version = "0.1.0"
edition = "2024"

[dependencies]
windows-threading = "0.1"

Crate code

fn main() {
    use windows_threading::Pool;
    let pool = Pool::new();
    pool.set_thread_limits(1, 2);
    pool.submit(|| {
        let s = "Hello, world!";
        pool.submit(|| println!("{s}"));
    });
    pool.join();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions