Re: [swift-users] Counting in Threads

2016-10-12 Thread Daniel Dunbar via swift-users
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 v

Re: [swift-users] Counting in Threads

2016-10-12 Thread Philippe Hausler via swift-users
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 attem

Re: [swift-users] Counting in Threads

2016-10-12 Thread Shawn Erickson via swift-users
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

Re: [swift-users] Counting in Threads

2016-10-12 Thread Philippe Hausler via swift-users
I was under the impression that taking the address was more than a single load instruction and would emit a placeholder invalid value: which would make that technically unsafe in a threaded context. Sent from my iPhone > On Oct 12, 2016, at 8:18 AM, Daniel Dunbar via swift-users > wrote: > >

Re: [swift-users] Counting in Threads

2016-10-12 Thread Daniel Dunbar via swift-users
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 init(_