-
Notifications
You must be signed in to change notification settings - Fork 245
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 Ticker issue #397 #407
Conversation
Why do we need to join the thread to be safe? I would argue that, once the Dropping the |
I think there's a race condition if |
Have you seen this happen? I'm still confused, can you spell out the order of events for me and why something would be bad? |
I have not seen it happen, no. The order of events would be:
Granted, it's a small window of opportunity. In practice I'd expect 99% of the time that the |
Also, to be clear - I certainly may be mistaken :). I'm not super experienced with multi-threaded Rust yet (or Rust in general for that matter). So please take this with a grain of salt. |
I'm also not super experienced with joining threads -- the |
(Also I still think we should merge this without blocking on that other stuff.) |
I'm also fine with merging this for now. And yeah the complexity would kind of suck :/. Since I'd also be fine with holding off on making any additional changes until (if) the hypothetical issue is uncovered in the wild. |
I suppose we could also add yet another layer of indirection, |
That might be what we have to do. Just to clarify, |
If |
The difference would be that
Maybe just this?
EDIT: actually maybe that's not strong enough. The above would guarantee the mutex is not held, but not that an |
I think checking the strong refcount in
|
I've been able to reproduce the race condition by using By default I have |
Awesome work making it testable! Maybe file it as a separate issue? I'm going to try to not think about it too much more today until after work. 😄 |
Thanks :). And sounds good, and will do! I'm going to investigate the possibility of adding some automated tests for But that will also have to wait until I'm done with some actual work today haha. |
I think there are two parts to #397:
MutexGuard<BarState>
, we also need to drop theArc<Mutex<BarState>>
, otherwise the reference count will never drop to 0 while the thread sleeps. The main thread will exit, but the destructor (on theTicker
thread's stack) will not run.join
theJoinHandle
. Trouble is I am not yet sure where to put thejoin
. It can't go in theDrop
impl forBarState
since then the thread would probably try to join itself. Perhaps we need to move the ticker state into anArc<Mutex<Option<TickerState>>>
inProgressBar
or something. Then we could rewriteTicker::run
to use, e.g.CondVar::wait_timeout
instead ofthread::sleep(self.interval)
.So more experimenting is necessary.