You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 28, 2020. It is now read-only.
public bool TryDequeue(IList<T> outputItems)
{
var entity = m_Entity as Entity;
int count = entity.Count;
if (count <= 0)
return false;
....
}
修改为
public bool TryDequeue(IList<T> outputItems)
{
var entity = m_Entity as Entity;
if (entity == m_BackEntity)
return false;
int count = entity.Count;
if (count <= 0)
return false;
....
}
读源码发现ConcurrentBatchQueue的TryDequeue可能有线程安全问题,经过测试发现问题确实存在。我的测试方法是开两个线程写数据,一个线程写1到1000,另一个线程写1001到2000,然后再开N个线程读数据,读够2000个数据后,把读出来的数据排序然后对比是否为1到2000的连续数字,如果是则测试成功,否则失败。测试结果与预期一致,单线程读多线程写没有线程安全问题,多线程读则会读到重复的数字,修改源码判断是否有其他线程正在 读之后,问题消除。
修改为