Threads2 wrong solution possible

オープン
#2,200 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

@GolakiyaVishal がすでに取り組んでいます。

2026年9月24日 から。

  • #2454 @GolakiyaVishal による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
rust
領域
testing

調査の方向性

まず threads2 演習と、期待される結果 10 を受け入れている検証を見つけます。示されている解答を再現して抜け穴を確認し、その後、解答ファイルと出力がどのように検証されているかを調べます。不正な解答が拒否され、正しい threads2 の解答は引き続き受け入れられれば完了です。

索引モデルが issue の本文から書いたものです。

説明

It is possible to pass threads2 without actually solving a task. Following code will make it great and allow to pass while being wrong. Maybe worth discarding as you can still get it by matching with expected result(10) and checking solution file

use std::{sync::Arc, thread, time::Duration};

#[derive(Clone)]
struct JobStatus {
    jobs_done: u32,
}

fn main() {
    // TODO: `Arc` isn't enough if you want a **mutable** shared state.
    let status = Arc::new(JobStatus { jobs_done: 0 });

    let mut handles = Vec::new();
    for _ in 0..10 {
        let mut status_shared = Arc::clone(&status);
        let handle = thread::spawn(move || {
            thread::sleep(Duration::from_millis(250));

            // TODO: You must take an action before you update a shared value.
            Arc::make_mut(&mut status_shared).jobs_done += 1;
        });
        handles.push(handle);
    }

    // Waiting for all jobs to complete.
    for handle in handles {
        handle.join().unwrap();
    }

    // TODO: Print the value of `JobStatus.jobs_done`.
    println!("Jobs done: {}", status.jobs_done);
}
主要言語
Rust
スター
64.6k
フォーク
11.3k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rustlings のほかの issue

rust-lang/rustlings の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。