Skip to content

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

@bkase

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions