<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 14, 2019 at 12:20 AM Derek Lesho <<a href="mailto:dlesho@codeweavers.com">dlesho@codeweavers.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    pthread_spin_lock(descriptor->lock);
<br></blockquote><div><br></div><div>I think this isn't thread safe. If a thread tries to lock descriptor->lock when another thread has memset the descriptor to 0, it will crash if pthread_spin_lock() doesn't check for null.</div><div><br></div><div>For performance reasons I think we need to test the possibility that any thread which meets a locked descriptor can skip the operation entirely. This would save spinning on the lock and an extra descriptor write. If two threads are writing the same descriptor simultaneously, this implies it's essentially random which thread sets what data, so maybe it will work if only the first thread writes the descriptor. Skipping can be done with pthread_spin_trylock(), but InterlockedCompareExchange() would be simpler.<br></div></div></div>