- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Overhaul and make Condvar::wait_timeout public #21132
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
Conversation
c015489    to
    34dd78a      
    Compare
  
    | 
           I think there's a pretty easy tweak that can be made to wait_timeout_with to fix the poison issue, but I'm too tired to properly think it through right now. I'll fix it up tomorrow.  | 
    
| 
           Another thing to consider here is that we may want to rename   | 
    
        
          
                src/libstd/sys/unix/condvar.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this use .checked_add to check for overflow instead?
          
 One possibly very weird thing to do would be to give the closure   | 
    
| 
           I don't think it'd need to return anything other than the   | 
    
| 
           I was thinking it could commonly be called as: foo.wait_timeout_with(lock, duration, |state| Ok(try!(state).condition()));The   | 
    
| 
           I think we need to work out conventions on how the poisoning stuff should actually be used. My thought was you have the common cases where you don't expect to be poisoned, so you just unwrap and propagate the failure, or you don't care about poisoning so you'd call some method on LockResult to just give you the MutexGuard no matter what.  | 
    
| 
           Yeah currently those looks like: foo.unwrap() // assertion that "a poison is bad"
foo.unwrap_or_else(|e| e.into_guard()) // assertion that "I'm ok with poisons" | 
    
| 
           Just pushed fixes up in a new commit.  | 
    
b69c0e5    to
    a4d9a7e      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was lost in movement to a different location
| 
           Updated  | 
    
        
          
                src/libstd/sync/condvar.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry when I said &mut T I meant:
where F: FnMut(LockResult<&mut T>) -> boolThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sure that seems reasonable. We'll definitely want to rename into_guard then though.
| 
           Ok this is all looking pretty good to me, would like @aturon's opinion as well, however.  | 
    
fe909aa    to
    d2d46c1      
    Compare
  
    | 
           Re-updated. Ideally, the function would take a  EDIT: Oh wait, that lifetime wouldn't make any sense at all.  | 
    
| 
           So, I'm basically fine with this as an initial, experimental API. In the long run, I'd like to nix the   | 
    
| 
           r=me with a squash  | 
    
9ae4954    to
    36ea376      
    Compare
  
    9881c4a    to
    5639f78      
    Compare
  
    **The implementation is a direct adaptation of libcxx's condition_variable implementation.** pthread_cond_timedwait uses the non-monotonic system clock. It's possible to change the clock to a monotonic via pthread_cond_attr, but this is incompatible with static initialization. To deal with this, we calculate the timeout using the system clock, and maintain a separate record of the start and end times with a monotonic clock to be used for calculation of the return value.
5639f78    to
    08f6380      
    Compare
  
    **The implementation is a direct adaptation of libcxx's condition_variable implementation.** I also added a wait_timeout_with method, which matches the second overload in C++'s condition_variable. The implementation right now is kind of dumb but it works. There is an outstanding issue with it: as is it doesn't support the use case where a user doesn't care about poisoning and wants to continue through poison. r? @alexcrichton @aturon
**The implementation is a direct adaptation of libcxx's condition_variable implementation.** I also added a wait_timeout_with method, which matches the second overload in C++'s condition_variable. The implementation right now is kind of dumb but it works. There is an outstanding issue with it: as is it doesn't support the use case where a user doesn't care about poisoning and wants to continue through poison. r? @alexcrichton @aturon
The implementation is a direct adaptation of libcxx's condition_variable implementation.
I also added a wait_timeout_with method, which matches the second overload in C++'s condition_variable. The implementation right now is kind of dumb but it works. There is an outstanding issue with it: as is it doesn't support the use case where a user doesn't care about poisoning and wants to continue through poison.
r? @alexcrichton @aturon