If we decided to delete a mapping entry we did not act on it right away
but first issued and waited for memory copies. In the meantime some
other thread might reuse the entry. While there was some logic to avoid
colliding on the actual "deletion" part, there were two races happening:
- The data transfer back of the thread deleting the entry and the data transfer back of the thread taking over the entry raced.
- The update to the shadow map happened regardless if the entry was actually reused by another thread which left the shadow map in a inconsistent state.
To fix both issues we will now update the shadow map and delete the
entry only if we are sure the thread is responsible for deletion, hence
no other thread took over the entry and reused it. We also wait for a
potential former data transfer from the device to finish before we issue
another one that would race with it.
Unfortunately, __kmpc_global_thread_num cannot give you a unique id. I did a simple test:
It prints:
Since libomptarget is not forced to use OpenMP thread, we cannot use functions in libomp to tell thread id. std::thread::id should be used here I think.