[swift-users] بخصوص: Swift 4.0 bug in concurrent array access

Jordan Rose jordan_rose at apple.com
Mon Jan 8 14:51:18 CST 2018



> On Jan 8, 2018, at 11:47, ⁨‫Fadi Botros‬ ‫⁩ <⁨botros_fadi at yahoo.com⁩> wrote:
> 
> 1st: How to invoke the thread sanitizer?

Check out this article on developer.apple.com: https://developer.apple.com/documentation/code_diagnostics/thread_sanitizer/enabling_the_thread_sanitizer

> 2nd: I think making something like ConcurrentModificationException of Java should be a little better experience (if it will not make, or make a small performance penalty, also if it makes performance penalty, it would be activated only when you make a debug version or non-optimized version)

I don't exactly disagree, but my understanding is that the work to do such a thing is nearly equivalent to having thread sanitizer on all the time. But maybe there's a simpler model that we could still turn on in debug builds. Can you file a bug report requesting this now that bugs.swift.org is back up?

Thanks!
Jordan



> 
> 
> من: Jordan Rose <jordan_rose at apple.com>
> إلى: ‫Fadi Botros‬ ‫ <botros_fadi at yahoo.com> 
> نسخة كربونية: "swift-users at swift.org" <swift-users at swift.org>
> تاريخ الإرسال: الإثنين 8 يناير، 2018‏ 9:14 م
> الموضوع: Re: [swift-users] Swift 4.0 bug in concurrent array access
> 
> That sounds expected to me. While Array values are thread-safe, writing to the global variable 'array' from two different threads would be a race. You can see this properly diagnosed if you enable Thread Sanitizer.
> 
> Jordan
> 
> P.S. bugs.swift.org <http://bugs.swift.org/> should be back up now, if you find any other issues.
> 
> 
>> On Jan 8, 2018, at 11:02, ⁨‫Fadi Botros‬ ‫ via swift-users⁩ <⁨swift-users at swift.org <mailto:swift-users at swift.org>⁩> wrote:
>> 
>> I'm on macOS Sierra 10.12.6, and using Swift 4.0
>> Tried to access the array concurrently to see whether is it synchronized or no
>> import Foundation let global = DispatchQueue.global() var array: [Int] = [ - Pastebin.com <https://pastebin.com/PnvyM3Qn>
>> 
>> 
>> import Foundation let global = DispatchQueue.global() var array: [Int...
>>  <https://pastebin.com/PnvyM3Qn>
>> 
>> When tried to run it using the terminal
>> This crash happened
>> 
>> swift(69836,0x700002dc2000) malloc: *** error for object 0x7ffe4be237e0: pointer - Pastebin.com <https://pastebin.com/vrdKTfrP>
>> 
>> 
>> swift(69836,0x700002dc2000) malloc: *** error for object 0x7ffe4be237e0: po...
>>  <https://pastebin.com/vrdKTfrP>
>> 
>> Avoided this crash using Serial Dispatch Queue
>> 
>> let otherDispatch = DispatchQueue(label: "another.dispatch.com <http://another.dispatch.com/>",
>>                                   qos: .default)
>> func appending(_ i: Int) {
>>   otherDispatch.sync { array.append(i) }
>> }
>> 
>> 
>> 
>> Also tried to file this issue on bugs.swift.org <http://bugs.swift.org/>, and it appears your site is down (under maintainence)
>> 
>> Sorry
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org <mailto:swift-users at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20180108/edf8dc2a/attachment.html>


More information about the swift-users mailing list