Not in this case, today:
--
$ cat x.swift
import Darwin.C
public class AtomicInt32 {
public fileprivate (set) var value : Int32 = 0
/// Create a new atomic integer with the specified initial value.
public init(_ value: Int32 = 0) {
self.value = value
}
/// Add one to the
Or allocate a pointer for it. The other alternative would be NSLock but that
might be swatting flies with sledgehammers. We had a similar issue implementing
NSLock in swift-corelibs-foundation where taking the address of a pthread mutex
corrupted the structure for when another thread would
So we would have to drop down to C code, etc. to safely leverage OSAtomic?
On Wed, Oct 12, 2016 at 8:32 AM Philippe Hausler via swift-users <
swift-users@swift.org> wrote:
> I was under the impression that taking the address was more than a single
> load instruction and would emit a placeholder
I suspect one of the actual compiler people might tell me I shouldn't trust
this, but in practice it works:
--
import Darwin.C
public class AtomicInt32 {
public fileprivate (set) var value : Int32 = 0
/// Create a new atomic integer with the specified initial value.
public
How to translate this to Swift:
__block atomic_uint_fast64_t counter = ATOMIC_VAR_INIT(0);
dispatch_apply( nbrInterations, queue, ^void(size_t idx)
{
uint64_t tCount = 0;
... do some counting ...
atomic_fetch_add_explicit( , tCount,