Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: check if a thread is still alive after the block is dead #1875

Conversation

meship-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

github-actions bot commented Nov 7, 2024

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from b043b17 to 21f541e Compare November 7, 2024 14:54
Copy link

github-actions bot commented Nov 7, 2024

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from 21f541e to b043b17 Compare November 7, 2024 15:12
Copy link

github-actions bot commented Nov 7, 2024

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from b043b17 to 95cbeac Compare November 10, 2024 07:57
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware changed the title chore: check if a thread is still alive after the block is dead. chore: check if a thread is still alive after the block is dead Nov 10, 2024
Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

Attention: Patch coverage is 37.77778% with 28 lines in your changes missing coverage. Please review.

Project coverage is 9.68%. Comparing base (e3165c4) to head (843ef70).
Report is 482 commits behind head on main.

Files with missing lines Patch % Lines
crates/native_blockifier/src/py_block_executor.rs 37.77% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #1875       +/-   ##
==========================================
- Coverage   40.10%   9.68%   -30.43%     
==========================================
  Files          26     133      +107     
  Lines        1895   16999    +15104     
  Branches     1895   16999    +15104     
==========================================
+ Hits          760    1646      +886     
- Misses       1100   15029    +13929     
- Partials       35     324      +289     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from 95cbeac to 50376de Compare November 10, 2024 08:15
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from 50376de to e69a679 Compare November 11, 2024 10:44
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from e69a679 to 6439574 Compare November 11, 2024 11:21
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from 6439574 to a0d8e60 Compare November 11, 2024 11:27
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from a0d8e60 to efda8d0 Compare November 11, 2024 13:42
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from efda8d0 to 3507ca0 Compare November 12, 2024 12:54
Copy link

Artifacts upload triggered. View details here

Comment on lines 137 to 151
fn thread_logic(shared_struct: Arc<Mutex<Option<MyStruct>>>) {
let mut shared_struct = shared_struct.lock().unwrap();
*shared_struct = Some(MyStruct { a: 1, b: 2 });
loop {
let my_struct = shared_struct.as_ref().unwrap();
println!("MyStruct is accessible: a = {}, b = {}", my_struct.a, my_struct.b);
thread::sleep(std::time::Duration::from_secs(1));
if my_struct.a >= 2 && my_struct.a <= 5 {
println!("Mystuct.a: {} is between 2 and 5", my_struct.a);
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thread_logic function currently holds the mutex lock for the entire duration of the infinite loop, which creates a high risk of deadlock. The lock should be acquired and released in each loop iteration. Here's a safer approach:

let my_struct = {
    let guard = shared_struct.lock().unwrap();
    guard.as_ref().unwrap().clone()
};

This pattern ensures the mutex is released promptly after each read operation, allowing other threads to access the shared data structure.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from 3507ca0 to 238aed1 Compare November 12, 2024 13:03
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware force-pushed the meship/sequencer/open_thred_inside_block_executor branch from 238aed1 to 843ef70 Compare November 14, 2024 13:26
Copy link

Artifacts upload triggered. View details here

@meship-starkware meship-starkware deleted the meship/sequencer/open_thred_inside_block_executor branch November 19, 2024 06:10
@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants