> On 13 Sep 2016, at 15:20, Quincey Morris > <quinceymor...@rivergatesoftware.com> wrote: > >> On Sep 13, 2016, at 00:57 , Gerriet M. Denkmann <gerr...@mdenkmann.de> wrote: >> >> I was struggling to find a solution which is thread safe. > > Your problem didn’t really need thread safety, though. There appeared to be > no data dependencies between the bitfield elements — each was written > independently and never read — so all you needed was atomicity to make sure > the underlying code didn’t trip over itself. Further, as you discovered, your > task was easily partitionable into *independent* data sections, so you didn’t > really need atomicity either, if your data storage was structured carefully. > > But I’m assuming none of this is true for your real goal, unless your real > goal is solely to initialize a big array using multiple CPUs.
My real problem is a pet project: a sieve of Eratosthenes (Ἐρατοσθένης) to find all primes up to a certain number. I use this to learn Swift, and to compare the performance of Swift to Objective-C. So I have this huge bitfield (which different subclasses implement differently) and I have to mark certain items in a certain range as non-prime (= true or 1). As the range to be marked changes as the algorithm proceeds, it makes no sense to have 8 sub-bitfields and give one each to a marking thread; at a later stage only the last sub-bitfield will need markings, and the algorithm would be again single threaded. I indeed need no atomicity: all threads have their own data section, which do not overlap. Everything works fine (in Swift as in Objective-C) with dispatch_apply, as long as the bitfield is malloced. In case of bitfield: [Bool] the solution suggested by Stephen J. Butler will probably also work (I am just implementing it). Kind regards, Gerriet. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com