サンプル
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
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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
コントラクト
- 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 &Scope argument
- 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
ソース
# 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",
]
[package]
name = "sample"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
crossbeam-utils = "=0.8.23"
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.
{"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"}
{
"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"
]
}
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);
}
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,
}
}
オリジンシーダー
匿名