Dec 18, 2012 at 2:44 PM
Edited Dec 18, 2012 at 2:45 PM

Hi, kerryjiang.

While reviewing your codes, I'm really beginning to wonder whether "ConcurrentBatchQueue" is thread-safe or not.


In the majority of cases, it works thread-safefly, but let's suppose as below.

1. Thread A is running "ConcurrentBatchQueue.TryEnqueue" method, and current running point is just before the "int oldCount = Interlocked.CompareExchange(ref entity.Count, expectedCount, count)"

2. Thread B is running ConcurentBatchQueue.TryDequeue method, and current running point is just after the "Interlocked.Exchange(ref m_Entity, m_BackEntity)"


Under this situation, let's suppose that only "Thread B" is currently focused by CPU, so it start to proceed, and the current running point of "Thread B" became "m_BackEntity = entity", and then, "Thread A" is suddenly focused by CPU and suppose that it start to run.

In this case, the dequeue process is already finished, but "Thread A" is try to enqueue data, but the enqueing point of "Thread A" will be invalid point, isn't it ?


Please answer to this question. Is it really thread-safe?



Dec 18, 2012 at 2:54 PM

Yes, you are correct!

I also found issues of ConcurrentBatchQueue, now I am busy on fixing them. It blocks the release of SuperSocket 1.5

Jan 11, 2013 at 4:03 AM

Hi, I have changed the implementation of SendingQueue in SuperSocket 1.5 stable.