CodeSampleX

샘플

crossbeam-utils 0.8.23: crossbeam_utils::thread

검증된 샘플 — cargo crossbeam-utils 0.8.23: crossbeam_utils::thread. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: crossbeam_utils::thread::scope…

sha256:0424eb2a1d48cc1be03639f709b4f520f3d2140103072cee3854890f67016b0c

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux x64 cargo

검증 실행 환경

환경 컨트랙트 단계 실행일
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-06

케이스

HOW
목표
verify crossbeam_utils::thread in pkg:cargo/crossbeam-utils@0.8.23
패키지
심벌
  • crossbeam_utils::thread
생성일
2026-11-06T04:32:46Z

컨트랙트

  1. crossbeam_utils::thread::scope spawns scoped threads via Scope::spawn and ScopedThreadBuilder::spawn that borrow non-'static stack slices concurrently without moving ownership
  2. ScopedJoinHandle::join returns Ok with each thread's computed value, and Scope allows nested spawning from within a child closure via the inner &Scope argument
  3. Calling join() on a panicking scoped thread returns Err and prevents the panic from causing the outer thread::scope call to return Err

파일

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs
  • tests/contract.rs

소스 아티팩트 내려받기 (tar.gz)

소스

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "crossbeam-utils"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"

[[package]]
name = "sample"
version = "0.1.0"
dependencies = [
 "crossbeam-utils",
]
Cargo.toml
[package]
name = "sample"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
crossbeam-utils = "=0.8.23"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify crossbeam_utils::thread in pkg:cargo/crossbeam-utils@0.8.23
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/crossbeam-utils@0.8.23
Demonstrate these symbols/APIs:
  - crossbeam_utils::thread

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:be373a82d5721b80ae5f0e6368e59834c2d2dd82b71c2d2b09556dbc874fe35a","contract":["crossbeam_utils::thread::scope spawns scoped threads via Scope::spawn and ScopedThreadBuilder::spawn that borrow non-'static stack slices concurrently without moving ownership","ScopedJoinHandle::join returns Ok with each thread's computed value, and Scope allows nested spawning from within a child closure via the inner \u0026Scope argument","Calling join() on a panicking scoped thread returns Err and prevents the panic from causing the outer thread::scope call to return Err"],"goal":"verify crossbeam_utils::thread in pkg:cargo/crossbeam-utils@0.8.23","kind":"HOW","packages":["pkg:cargo/crossbeam-utils@0.8.23"],"schemaVersion":1,"symbols":["crossbeam_utils::thread"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/crossbeam-utils@0.8.23"],"schemaVersion":1,"subject":"pkg:cargo/crossbeam-utils@0.8.23","symbols":["crossbeam_utils::thread"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify crossbeam_utils::thread in pkg:cargo/crossbeam-utils@0.8.23",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/crossbeam-utils@0.8.23"
  ],
  "symbols": [
    "crossbeam_utils::thread"
  ]
}
src/main.rs
use crossbeam_utils::thread::{scope, Scope, ScopedJoinHandle, ScopedThreadBuilder};
use std::sync::atomic::{AtomicUsize, Ordering};

pub fn scoped_borrow_sum(values: &[i64]) -> i64 {
    let mid = values.len() / 2;
    let (left, right) = values.split_at(mid);
    scope(|s: &Scope<'_>| {
        let left_handle: ScopedJoinHandle<'_, i64> = s.spawn(|_| left.iter().copied().sum());
        let right_builder: ScopedThreadBuilder<'_, '_> = s.builder().name("right-sum".to_string());
        let right_handle: ScopedJoinHandle<'_, i64> = right_builder
            .spawn(|_| {
                assert_eq!(std::thread::current().name(), Some("right-sum"));
                right.iter().copied().sum()
            })
            .expect("spawn named scoped thread");
        let left_sum = left_handle.join().expect("left join");
        let right_sum = right_handle.join().expect("right join");
        left_sum + right_sum
    })
    .expect("scope completed without unhandled panic")
}

pub fn nested_spawn_from_inner_scope(steps: usize) -> usize {
    let counter = AtomicUsize::new(0);
    scope(|s| {
        s.spawn(|inner| {
            for _ in 0..steps {
                inner.spawn(|_| {
                    counter.fetch_add(1, Ordering::SeqCst);
                });
            }
        });
    })
    .expect("nested scope completed");
    counter.load(Ordering::SeqCst)
}

fn main() {
    let data = [10_i64, 20, 30, 40, 50, 60];
    let total = scoped_borrow_sum(&data);
    assert_eq!(total, 210);

    let nested = nested_spawn_from_inner_scope(4);
    assert_eq!(nested, 4);
}
tests/contract.rs
include!("../src/main.rs");

#[test]
fn contract_scoped_threads_borrow_and_join() {
    let local_vec = vec![1_i64, 2, 3, 4, 5, 6, 7, 8];
    let sum = scoped_borrow_sum(&local_vec);
    assert_eq!(sum, 36);
    assert_eq!(local_vec.len(), 8);
}

#[test]
fn contract_nested_scoped_spawns_and_panic_propagation() {
    assert_eq!(nested_spawn_from_inner_scope(5), 5);

    let mut mutated_in_place = [1_u32, 2, 3, 4];
    let out = crossbeam_utils::thread::scope(|s| {
        let (first_half, second_half) = mutated_in_place.split_at_mut(2);
        let h1 = s.spawn(|_| {
            for v in first_half.iter_mut() {
                *v *= 10;
            }
            first_half[0] + first_half[1]
        });
        let h2 = s
            .builder()
            .name("worker-2".to_string())
            .spawn(|_| {
                assert_eq!(h2_thread_name(), Some("worker-2"));
                for v in second_half.iter_mut() {
                    *v *= 10;
                }
                second_half[0] + second_half[1]
            })
            .expect("builder spawn should succeed");
        assert_eq!(h2.thread().name(), Some("worker-2"));
        h1.join().unwrap() + h2.join().unwrap()
    })
    .expect("scope should succeed");

    assert_eq!(out, 100);
    assert_eq!(mutated_in_place, [10, 20, 30, 40]);

    // Verify that joining a panicking scoped thread captures the panic in Err
    // so the enclosing scope itself succeeds with Ok.
    let handled = crossbeam_utils::thread::scope(|s| {
        let h = s.spawn(|_| -> i32 {
            panic!("expected scoped child panic");
        });
        h.join().is_err()
    })
    .expect("scope returns Ok when child panic is consumed via join");
    assert!(handled);
}

fn h2_thread_name() -> Option<&'static str> {
    match std::thread::current().name() {
        Some("worker-2") => Some("worker-2"),
        _ => None,
    }
}

오리진 시더

익명