<div dir="ltr">Ahh! thank you. That makes sense. </div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 1, 2017 at 3:29 PM, Guillaume Lessard <span dir="ltr">&lt;<a href="mailto:glessard@tffenterprises.com" target="_blank">glessard@tffenterprises.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
&gt; On Mar 1, 2017, at 3:21 PM, Edward Connell via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; The thread sanitizer on Linux is reporting that I have race conditions in libswiftcore. I eliminated enough code down to this trivial example. Is there really a race condition here or are these bogus errors?<br>
&gt;<br>
&gt;       let count = 1000<br>
&gt;       var items = [[UInt8]?](repeating: nil, count: count)<br>
&gt;<br>
&gt;       DispatchQueue.<wbr>concurrentPerform(iterations: count) {<br>
&gt;               items[$0] = [UInt8](repeating: 7, count: 10)<br>
&gt;       }<br>
&gt;<br>
&gt; My real scenario is retrieving data asynchronously, so I just threw in a buffer assignment.<br>
<br>
</span>The assignments to array elements are where the race lies.<br>
<br>
I don’t know about the libswiftcore part, but: assigning to a shared Array concurrently from multiple threads won&#39;t work, because of Array&#39;s copy-on-write behaviour. You could do<br>
<br>
let items = UnsafeMutablePointer&lt;[UInt8]?&gt;<wbr>.allocate(capacity: 1)<br>
items.initialize(to: nil, count: count)<br>
<br>
DispatchQueue.<wbr>concurrentPerform(iterations: count) {<br>
  items[$0].initialize([UInt8](<wbr>repeating: 7, count: 10))<br>
}<br>
<br>
// you’ll be able to see here that they’re all initialized<br>
<br>
items.deallocate(capacity: count)<br>
<br>
Cheers,<br>
Guillaume Lessard<br>
<br>
</blockquote></div><br></div>