You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
We might somehow introduced data races (this should be nearly impossible in Rust, very curious to find out the exact cause). To start with, our current practice of using global variables wrapped in OnceCell and Arc with std::sync::mutex or tokio::sync::mutex might not be effectively preventing deadlock possibilities.
Expectation proposal
In theory, using a Mutex to access a global variable before passing it into async functions can be a valid approach to ensure safe concurrent access.
Review the approach to access global variables.
Redesign the concurrent aspects; Potentially create a global struct to contain all the variables
Make sure that async tasks acquire and release locks asynchronously and do not access global var directly.
Add timeouts to async functions to avoid threads sitting around forever
Alternative Considerations
Use RwLock: for global variable that is read-heavy and has infrequent writes, as RwLock multiple readers or a single writer.
Atomic Types: for simple primitive or atomic type.
Message Passing: to communicate and share data between async tasks.(tokio::sync::mpsc) to send data between tasks, as MPSC ensures that only one task has ownership of the data at a time and preventing concurrent access issues.
Problem statement
We ran into situations in which the radio gets stuck or unable to respond to query requests. For instance,
We might somehow introduced data races (this should be nearly impossible in Rust, very curious to find out the exact cause). To start with, our current practice of using global variables wrapped in
OnceCell
andArc
withstd::sync::mutex
ortokio::sync::mutex
might not be effectively preventing deadlock possibilities.Expectation proposal
In theory, using a Mutex to access a global variable before passing it into async functions can be a valid approach to ensure safe concurrent access.
Alternative Considerations
The text was updated successfully, but these errors were encountered: