Fix an error in new lockfree parallel_range_next_iter_get() helper.

Reading the shared state->iter value after storing it in the 'reference' var could in theory
lead to a race condition setting state->iter value above state->stop, which would be 'deadly'.

This **may** be the cause of T48422, though I was not able to reproduce that issue so far.
This commit is contained in:
Bastien Montagne 2016-05-14 18:02:34 +02:00
parent b9996a3cc3
commit a83bc4f597
Notes: blender-bot 2023-02-14 07:53:46 +01:00
Referenced by commit bb7da630ba, Fix T48422: Revert "BLI_task: nano-optimizations to BLI_task_parallel_range feature."
Referenced by issue #48442, Raycast + subsurf freeze blender
Referenced by issue #48432, Blender locks up almost instantly when starting to sculpt on a multires object.
1 changed files with 2 additions and 2 deletions

View File

@ -784,13 +784,13 @@ BLI_INLINE bool parallel_range_next_iter_get(
{
uint32_t n, olditer, previter, newiter;
if (state->iter >= state->stop) {
if (UNLIKELY(state->iter >= state->stop)) {
return false;
}
do {
olditer = state->iter;
n = min_ii(state->chunk_size, state->stop - state->iter);
n = min_ii(state->chunk_size, state->stop - olditer);
newiter = olditer + n;
previter = atomic_cas_uint32((uint32_t *)&state->iter, olditer, newiter);
} while (UNLIKELY(previter != olditer));