Skip to content

Commit

Permalink
Fixed potential threading error in enumeration modifiable concurrent …
Browse files Browse the repository at this point in the history
…list (#60)

* because when the pool had an element and it was retrieved by another thread than the current, we tried to load get it a second time, which crashed, so we need to check the pool again after we got the lock
  • Loading branch information
susch19 authored Sep 6, 2023
1 parent 88b893e commit 72590c0
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,14 @@ public Enumerator Get()
Enumerator item;
using (var __ = scopeSemaphore.EnterExclusivScope())
{
item = pool.Pop();
item.Reset();
gottem.Add(item);
if (pool.Count > 0)
{
item = pool.Pop();
item.Reset();
gottem.Add(item);
return item;
}
}
return item;
}

var e = new Enumerator(list);
Expand Down

0 comments on commit 72590c0

Please sign in to comment.