Re: Swift: another crash
Re: Swift: another crash
- Subject: Re: Swift: another crash
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Tue, 08 Jul 2014 18:28:47 +0700
On 8 Jul 2014, at 18:20, Roland King <email@hidden> wrote:
> theCounts[ Int(idx) ] = localCount;
>
> That doesn’t look very thread-safe.
Obviously the current Swift arrays are not thread-safe.
My workaround:
class Summer
{
var value : UInt = 0
}
var otherCounts = [Summer]()
for i in 0..<nbrOfThreads { otherCounts.append( Summer() ) }
dispatch_apply( nbrOfThreads, queue,
{ (idx: size_t) in
var localCount : UInt = idx
otherCounts[ Int(idx) ].value = localCount;
}
)
Seems to be working so far.
Gerriet.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden