In Swift 3 and on iOS 10 and macOS Sierra you can utilize a subset of the <stdatomic.h> C library.
This is the synthesized header:
/* 7.17.1 Introduction */
public var ATOMIC_BOOL_LOCK_FREE: Int32 { get }
public var ATOMIC_CHAR_LOCK_FREE: Int32 { get }
public var ATOMIC_CHAR16_T_LOCK_FREE: Int32 { get }
public var ATOMIC_CHAR32_T_LOCK_FREE: Int32 { get }
public var ATOMIC_WCHAR_T_LOCK_FREE: Int32 { get }
/* 7.17.2 Initialization */
/* 7.17.3 Order and consistency */
public struct memory_order : RawRepresentable, Equatable {
public init(_ rawValue: UInt32)
public init(rawValue: UInt32)
public var rawValue: UInt32
}
public var memory_order_relaxed: memory_order { get }
public var memory_order_consume: memory_order { get }
public var memory_order_acquire: memory_order { get }
public var memory_order_release: memory_order { get }
public var memory_order_acq_rel: memory_order { get }
public var memory_order_seq_cst: memory_order { get }
/* 7.17.4 Fences */
/* These should be provided by the libc implementation. */
public func atomic_thread_fence(_: memory_order)
public func atomic_signal_fence(_: memory_order)
/* 7.17.5 Lock-free property */
/* 7.17.6 Atomic integer types */
/* 7.17.7 Operations on atomic types */
/* 7.17.8 Atomic flag type and operations */
public struct atomic_flag {
public init()
}
/* These should be provided by the libc implementation. */
public func atomic_flag_test_and_set(_: UnsafeMutablePointer<atomic_flag>!) -> Bool
public func atomic_flag_test_and_set_explicit(_: UnsafeMutablePointer<atomic_flag>!, _: memory_order) -> Bool
public func atomic_flag_clear(_: UnsafeMutablePointer<atomic_flag>!)
public func atomic_flag_clear_explicit(_: UnsafeMutablePointer<atomic_flag>!, _: memory_order)