• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swift and Threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift and Threads


  • Subject: Re: Swift and Threads
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Tue, 13 Sep 2016 15:56:42 +0700

> On 13 Sep 2016, at 15:20, Quincey Morris <email@hidden> wrote:
>
>> On Sep 13, 2016, at 00:57 , Gerriet M. Denkmann <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >Swift and Threads (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Swift and Threads (From: Jens Alfke <email@hidden>)
 >Re: Swift and Threads (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Swift and Threads (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Swift and Threads
  • Next by Date: Strange toolbar item error
  • Previous by thread: Re: Swift and Threads
  • Next by thread: Strange toolbar item error
  • Index(es):
    • Date
    • Thread