<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px">What about double checking?<div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" id="yui_3_16_0_ym19_1_1515461367163_13194" style="display: block;"><div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 13px;" id="yui_3_16_0_ym19_1_1515461367163_13193"><div style="font-family: HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_ym19_1_1515461367163_13192"><div class="y_msg_container" id="yui_3_16_0_ym19_1_1515461367163_13206"><div id="yiv0211351497"><div id="yui_3_16_0_ym19_1_1515461367163_13205"><div style="color:#000;background-color:#fff;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;" id="yui_3_16_0_ym19_1_1515461367163_13204"><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10288"><br clear="none"></div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10289">Something like that</div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10393"><br clear="none"></div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10394">if counter != 0 { throw exc }<br clear="none"></div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10395">counter += 1</div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10396">if counter != 1 { throw exc }</div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10397">counter += 1<br clear="none"></div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10260"><span><br clear="none"></span></div><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10399"><span id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10398">I think the performance penalty is just a check and an increment<br clear="none"></span></div><div><span id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10398">It could be disabled after optimization or in release version to increase performance</span></div><div class="yiv0211351497qtdSeparateBR" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10233"><br clear="none"><br clear="none"></div><div class="yiv0211351497yqt6302841969" id="yiv0211351497yqt45576"><div class="yiv0211351497yahoo_quoted" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10225" style="display:block;">  <div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10224" style="font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;"> <div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10223" style="font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"> <div dir="rtl" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10222"> <font id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10221" size="2" face="Arial"> </font><hr id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10400" size="1"> <b id="yui_3_16_0_ym19_1_1515461367163_13208"><span style="font-weight:bold;" id="yui_3_16_0_ym19_1_1515461367163_13207">من:</span></b> Greg Parker &lt;gparker@apple.com&gt;<br clear="none"> <b id="yui_3_16_0_ym19_1_1515461367163_13210"><span style="font-weight:bold;" id="yui_3_16_0_ym19_1_1515461367163_13209">إلى:</span></b> Chris Lattner &lt;clattner@nondot.org&gt; <br clear="none"><b id="yui_3_16_0_ym19_1_1515461367163_13212"><span style="font-weight:bold;" id="yui_3_16_0_ym19_1_1515461367163_13211">نسخة كربونية:</span></b> Jordan Rose &lt;jordan_rose@apple.com&gt;; swift-users &lt;swift-users@swift.org&gt;; ‫Fadi Botros‬ ‫ &lt;botros_fadi@yahoo.com&gt;<br clear="none"> <b id="yui_3_16_0_ym19_1_1515461367163_13214"><span style="font-weight:bold;" id="yui_3_16_0_ym19_1_1515461367163_13213">تاريخ الإرسال:</span></b> الثلاثاء 9 يناير، 2018‏ 3:47 ص<br clear="none"> <b id="yui_3_16_0_ym19_1_1515461367163_13216"><span style="font-weight:bold;" id="yui_3_16_0_ym19_1_1515461367163_13215">الموضوع:</span></b> Re: [swift-users] بخصوص:  Swift 4.0 bug in concurrent array access<br clear="none">  </div> <div class="yiv0211351497y_msg_container" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10226"><br clear="none"><div id="yiv0211351497"><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10227"><br class="yiv0211351497" clear="none"><div id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10406"><blockquote class="yiv0211351497" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10405" type="cite"><div class="yiv0211351497" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10404">On Jan 8, 2018, at 5:20 PM, Chris Lattner &lt;<a rel="nofollow" shape="rect" class="yiv0211351497" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10403" ymailto="mailto:clattner@nondot.org" target="_blank" href="mailto:clattner@nondot.org">clattner@nondot.org</a>&gt; wrote:</div><div class="yiv0211351497" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10408"><div class="yiv0211351497" id="yiv0211351497yui_3_16_0_ym19_1_1515461367163_10407" style="word-wrap:break-word;"><br class="yiv0211351497" clear="none"><div class="yiv0211351497"><blockquote class="yiv0211351497" type="cite"><div class="yiv0211351497">On Jan 8, 2018, at 2:59 PM, Greg Parker via swift-users &lt;<a rel="nofollow" shape="rect" class="yiv0211351497" ymailto="mailto:swift-users@swift.org" target="_blank" href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:</div><div class="yiv0211351497"><div class="yiv0211351497" style="word-wrap:break-word;"><br class="yiv0211351497" clear="none"><div class="yiv0211351497"><blockquote class="yiv0211351497" type="cite"><div class="yiv0211351497">On Jan 8, 2018, at 12:51 PM, Jordan Rose via swift-users &lt;<a rel="nofollow" shape="rect" class="yiv0211351497" ymailto="mailto:swift-users@swift.org" target="_blank" href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:</div><div class="yiv0211351497"><div class="yiv0211351497" style="word-wrap:break-word;"><div class="yiv0211351497"><br class="yiv0211351497" clear="none"><blockquote class="yiv0211351497" type="cite"><div class="yiv0211351497">On Jan 8, 2018, at 11:47, ⁨‫Fadi Botros‬ ‫⁩ &lt;⁨<a rel="nofollow" shape="rect" class="yiv0211351497" ymailto="mailto:botros_fadi@yahoo.com" target="_blank" href="mailto:botros_fadi@yahoo.com">botros_fadi@yahoo.com</a>⁩&gt; wrote:</div><br class="yiv0211351497Apple-interchange-newline" clear="none"><div class="yiv0211351497"><div class="yiv0211351497"><div class="yiv0211351497" style="background-color:rgb(255, 255, 255);"><div class="yiv0211351497">1st: How to invoke the thread sanitizer?</div></div></div></div></blockquote><div class="yiv0211351497"><br class="yiv0211351497" clear="none"></div><div class="yiv0211351497">Check out this article on <a rel="nofollow" shape="rect" class="yiv0211351497" target="_blank" href="http://developer.apple.com/">developer.apple.com</a>:&nbsp;<a rel="nofollow" shape="rect" class="yiv0211351497" target="_blank" href="https://developer.apple.com/documentation/code_diagnostics/thread_sanitizer/enabling_the_thread_sanitizer">https://developer.apple.com/documentation/code_diagnostics/thread_sanitizer/enabling_the_thread_sanitizer</a></div><br class="yiv0211351497" clear="none"><blockquote class="yiv0211351497" type="cite"><div class="yiv0211351497"><div class="yiv0211351497"><div class="yiv0211351497" style="background-color:rgb(255, 255, 255);"><div class="yiv0211351497" dir="ltr" id="yiv0211351497yui_3_16_0_ym19_1_1515440347138_7774">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)<br class="yiv0211351497" clear="none"></div></div></div></div></blockquote><div class="yiv0211351497"><br class="yiv0211351497" clear="none"></div><div class="yiv0211351497">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 <a rel="nofollow" shape="rect" class="yiv0211351497" target="_blank" href="http://bugs.swift.org/">bugs.swift.org</a> is back up?</div></div></div></div></blockquote><br class="yiv0211351497" clear="none"></div><div class="yiv0211351497">Something like ConcurrentModificationException ought to be cheaper than the thread sanitizer. The thread sanitizer works hard to detect every concurrency error. ConcurrentModificationException typically does something simple and cheap that catches errors sometimes but makes no attempt to be exhaustive.</div><div class="yiv0211351497"><br class="yiv0211351497" clear="none"></div><div class="yiv0211351497">Objective-C's fast enumeration protocol includes a mechanism like this. The collection can have a simple mutation counter, and the enumerator captures the counter's value at the start and checks that the value is unchanged as the enumeration proceeds.</div></div></div></blockquote><br class="yiv0211351497" clear="none"></div><div class="yiv0211351497">Does ObjC synchronize the mutation counter? &nbsp;My understanding is that that counter was used to detect mutation while iteration on a single thread, not across threads.</div></div></div></blockquote><br class="yiv0211351497" clear="none"></div><div>The mutation counter is not synchronized; this is safe for correct code. An un-synchronized counter can still sometimes catch mutations from other threads.</div><div class="yiv0211351497yqt1234784834" id="yiv0211351497yqtfd65293"><div><br class="yiv0211351497" clear="none"></div><div><br class="yiv0211351497" clear="none"></div><div>--&nbsp;</div></div><div><div class="yiv0211351497yqt1234784834" id="yiv0211351497yqtfd05657">Greg Parker &nbsp; &nbsp; </div><a rel="nofollow" shape="rect" class="yiv0211351497" ymailto="mailto:gparker@apple.com" target="_blank" href="mailto:gparker@apple.com">gparker@apple.com</a>&nbsp; &nbsp; &nbsp;Runtime Wrangler</div><div class="yiv0211351497yqt1234784834" id="yiv0211351497yqtfd21976"><div><br class="yiv0211351497" clear="none"></div><br class="yiv0211351497" clear="none"></div></div></div><br clear="none"><br clear="none"></div> </div> </div>  </div></div></div></div></div><br><br></div> </div> </div>  </div></div></body></html>