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

Fix static mut issues with routines #677

Merged
merged 3 commits into from
Jan 27, 2025
Merged

Fix static mut issues with routines #677

merged 3 commits into from
Jan 27, 2025

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Jan 24, 2025

Closes #661.

Ideally R_ROUTINES would be thread-local but that's currently inconvenient in unit tests.

@lionel- lionel- requested a review from DavisVaughan January 24, 2025 14:54
Comment on lines 50 to 56
// Now unwrap the definitions from our thread-safe type
let unwrapped: Vec<R_CallMethodDef> = R_ROUTINES
.lock()
.unwrap()
.iter()
.map(|def| def.inner)
.collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fairly surprised you dont get a warning about "dropping temporary value" since no one is holding the lock in a local variable here. I seem to get that all the time when doing stuff like this.

crates/harp/src/routines.rs Outdated Show resolved Hide resolved
crates/harp/src/routines.rs Outdated Show resolved Hide resolved
unsafe impl Send for CallMethodDef {}
unsafe impl Sync for CallMethodDef {}

static R_ROUTINES: Mutex<Vec<CallMethodDef>> = Mutex::new(vec![]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice I also tried this when fiddling with this one last week but got stuck on the R_CallMethodDef not being send+sync problem

Comment on lines +21 to +22
unsafe impl Send for CallMethodDef {}
unsafe impl Sync for CallMethodDef {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think my main comment is that #[harp::register] is pretty freaking magical. It generates some code that runs at application startup time in an OS specific way.

I guess we can assume that code is always run on a single thread? I have no idea how startup code gets run on a per OS basis. I just want to make sure this doesn't screw us up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're just saying it is fine to send these raw pointers across threads, which it is as long as you don't do anything with them. We're not introducing any new area of unsafety AFAICT.

@lionel- lionel- force-pushed the task/gd-static-mut branch from 6d2a559 to 49d2cfa Compare January 27, 2025 10:42
Base automatically changed from task/gd-static-mut to main January 27, 2025 10:47
@lionel- lionel- force-pushed the task/routines-static-mut branch from fc25a0d to ea72243 Compare January 27, 2025 10:50
@lionel- lionel- merged commit 3d7afa5 into main Jan 27, 2025
5 of 6 checks passed
@lionel- lionel- deleted the task/routines-static-mut branch January 27, 2025 10:53
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2025
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.

Fix compilation warnings for shared reference to mutable static
2 participants