Re: Swift and Threads
Re: Swift and Threads
- Subject: Re: Swift and Threads
- From: Jens Alfke <email@hidden>
- Date: Mon, 12 Sep 2016 08:49:56 -0700
> On Sep 12, 2016, at 6:42 AM, Gerriet M. Denkmann <email@hidden> wrote:
>
> So: is the code ok and the compiler broken in Debug mode?
> Or is the code fundamentally wrong and that it works in Release is just a fluke?
99% of the time it’s the latter. Which means you should try to debug the code. Did you set the breakpoint on malloc_error? What line of code is triggering it? Did you examine the values of variables? Did you run with the Address Sanitizer?
I don’t see a bug in your code itself, but I’m not sure about the thread-safety of Swift arrays. NSMutableArray isn’t thread-safe, and I think Swift follows the same general thread-safety conventions. On the other hand, it doesn’t look like the array gets resized in the threads since you allocate it with a given capacity, so the assignments shouldn’t be doing anything fancy like memory allocation.
(But on the other other hand, if Swift is smart enough [like C++] to specialize [Bool] as a true bit-array, then assigning to an array element does require thread-safety, since it will involve reading a byte from RAM, setting one bit, and writing it back. That’s not an atomic operation, so overlapping assignments can interfere with each other. It wouldn’t cause a crash, though, obviously.)
—Jens
_______________________________________________
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