Pressure Scenario: Send/Sync Trait Bounds

2026-08-30 浏览 (1)

Pressure Scenario: Send/Sync Trait Bounds

Skill Under Test

m07-concurrency

User Question

"Why am I getting E0277: Rc<T> cannot be sent between threads safely?"

Code Context

use std::rc::Rc;
use std::thread;

fn main() {
    let data = Rc::new(42);
    thread::spawn(move || {
        println!("{}", data);  // E0277
    });
}

Expected Behavior

  • Explain Send/Sync traits
  • Explain why Rc is !Send
  • Provide fix: use Arc instead
  • Quick reference for concurrency patterns
  • Reference to P.MTH.LCK.01, G.MTH.LCK.01 guidelines

Baseline Test (without skill)

Date: [To be filled]

Result:

  • Send/Sync explanation: [PASS/FAIL]
  • Rc !Send reason: [PASS/FAIL]
  • Arc fix: [PASS/FAIL]
  • Quick reference: [PASS/FAIL]
  • Guidelines: [PASS/FAIL]

Notes: [To be filled after test]

Post-Skill Test

Date: [To be filled]

Result:

  • Send/Sync explanation: [PASS/FAIL]
  • Rc !Send reason: [PASS/FAIL]
  • Arc fix: [PASS/FAIL]
  • Quick reference: [PASS/FAIL]
  • Guidelines: [PASS/FAIL]

Notes: [To be filled after test]

Edge Cases

  1. "What about RefCell?" → Should explain !Sync
  2. "Can I implement Send manually?" → Should warn about unsafe impl
  3. "Arc vs Mutex?" → Should explain shared ownership vs shared mutability

你可能感兴趣的文章

Agent Cache System

Rust Skills Tests

Agent Integration Test Scenarios

Domain Skills Test Scenarios

Rust-Router Test Scenarios

Ownership (m01) Test Scenarios

Unsafe-Checker Test Scenarios

Layer 2 Skills Test Scenarios

Pressure Scenario: When to Use unwrap()

Pressure Scenario: E0597 Lifetime Too Short

  • 所属分类: AI
  • 本文标签: rust
  • 版权声明: 本文链接 https://seaxiang.com/blog/NWmcvnmY