Skip to content

Swap is not atomic, is this by design? #51

Description

@bkase
/// 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions