<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Sep 4, 2017, at 12:18 PM, Pierre Habouzit <<a href="mailto:phabouzit@apple.com" class="">phabouzit@apple.com</a>> wrote:<br class=""><div><blockquote type="cite" class="">Something else I realized, is that this code is fundamentally broken in swift:<br class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class="">actor func foo()</div></div><div class=""><div class="">{</div></div><div class=""><div class=""> NSLock *lock = NSLock();</div></div><div class=""><div class=""> lock.lock();</div></div><div class=""><div class=""><br class=""></div></div><div class=""><div class=""> let compute = await someCompute(); <--- this will really break `foo` in two pieces of code that can execute on two different physical threads.</div></div><div class=""><div class=""> lock.unlock();</div></div><div class=""><div class="">}</div></div></blockquote><div class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The reason why it is broken is that mutexes (whether it's NSLock, pthread_mutex, os_unfair_lock) have to be unlocked from the same thread that took it. the await right in the middle here means that we can't guarantee it.</div></div></div></div></blockquote><div><br class=""></div><div>Agreed, this is just as broken as:</div><div><br class=""></div><div>func foo()<br class="">{<br class=""> let lock = NSLock()<br class=""> lock.lock()<br class=""><br class=""> someCompute {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> lock.unlock()</div><div> }<br class="">}</div><div><br class=""></div><div>and it is just as broken as trying to do the same thing across queues. Stuff like this, or the use of TLS, is just inherently broken, both with GCD and with any sensible model underlying actors. Trying to fix this is not worth it IMO, it is better to be clear that they are different things and that (as a programmer) you should *expect* your tasks to run on multiple kernel threads.</div><div><br class=""></div><div>BTW, why are you using a lock in a single threaded context in the first place??? ;-)</div><div><br class=""></div><div>-Chris</div><div><br class=""></div></div></body></html>