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
/// Atomically, take a value from the `MVar`, put a given new value in the
/// `MVar`, then return the `MVar`'s old value.
public func swap(_ x : A) -> A {
let old = self.take()
self.put(x)
return old
}
The thread using swap might context-switch right after the take completes before the put -- if another thread puts then, this put will block.
The text was updated successfully, but these errors were encountered:
Aha, you're absolutely correct! The atomicity of this is dependent on exclusive putters. We could implement this atomically by making it a primitive (taking all those locks and junk), but for now I'm just going to use #52 to update the docs.
Keeping this issue open as a feature request for a truly atomic swap.
The thread using
swap
might context-switch right after the take completes before the put -- if another thread puts then, this put will block.The text was updated successfully, but these errors were encountered: