Threads2 wrong solution possible
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start by locating the threads2 exercise and the validation that accepts the expected result of 10. Reproduce the shown solution to confirm the loophole, then inspect how the solution file and output are checked. Done means the incorrect solution is rejected while a correct threads2 solution remains accepted.
Written by the indexing model from the issue text.
Description
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);
}
- Dominant language
- Rust
- Stars
- 64.6k
- Forks
- 11.3k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rustlings
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
A-exercises C-enhancement P-low
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Proposal: German (Deutsch) translation for Community ExercisesMay be free again @mo8it claimed this 62 days ago, and no pull request is open. Open
rust-lang/rustlings#2445 · 4 comments · 2 reactions · 1 assignee ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
All issues in rust-lang/rustlings
Similar issues
-
good first issue help wanted program
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hffgzktbcc-blip/ounce-core#297 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nautechsystems/nautilus_trader#5631 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
bytecodealliance/rustix#1736 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
longbridge/gpui-kit#3871 ·
Maintainers usually reply within 1 day
-
area:models enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day