On 9/15/19 10:22 PM, Conor McCarthy wrote:
You're right, I did overlook that (descriptor->lock being NULL). I'll try your idea to discard writes when one is already in progress with SOTTR, that solution should be faster.On Sat, Sep 14, 2019 at 12:20 AM Derek Lesho <dlesho@codeweavers.com> wrote:
+ pthread_spin_lock(descriptor->lock);
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.
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.