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

Lint check for array-length-get-in-loop-init-leads-to-deadlock issue #31

Open
JosephCottam opened this issue Sep 1, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@JosephCottam
Copy link
Collaborator

Issue: Use of local_data().len()
Fix: Replace with num_elems_local()
Reason: They return the same value, but local_data (sometimes) grabs a lock that might not be released as quickly as expected (e.g., during loop initialization the lock is kept for the lifetime of the loop, not just the lifetime of the initialization).

While developing a benchmark using a LocalLockArray, the "issue" version was used in a loop init that also included an array put (e.g., for i in 0...array.local_data().len() {array.put(i, ...)}). Switching the loop init to 0...array.num_elems_local() fixed the problem. The issue only comes up for LocalLockArray, but the change is valid on all array types.

Can we make a clippy check (or similar) for this?

@JosephCottam JosephCottam added the enhancement New feature or request label Sep 1, 2023
@JosephCottam JosephCottam self-assigned this Sep 1, 2023
@JosephCottam JosephCottam changed the title Lint check for possible locking issue Lint check for array-length-get-in-loop-init-leads-to-deadlock issue Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant