#1 2022-01-20 11:37:42

okoba
Member
Registered: 2019-09-29
Posts: 106

TSynQueue.Count

Hi,

TSynQueue.Count method uses ReadOnlyLock, and it makes problems when the Queue is shared between threads that are using the count while others are reading from or writing into it.
It was a weird error to find but in some cases it trough exceptions and maybe it is a good idea to use ReadWriteLock instead in Count. In my case it solved the issue like this:

   with Queue do
        try
          Safe.ReadWriteLock;
          QueueCount := Queue.Count;
        finally
          Safe.ReadWriteUnLock;
        end;     

Offline

#2 2022-01-20 17:53:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: TSynQueue.Count

I guess Count is of little help in practice. The useful property is Pending.

I have fixed TSynQueue.Count usage with
See https://github.com/synopse/mORMot2/commit/bcc9b351

Offline

#3 2022-01-22 08:13:18

okoba
Member
Registered: 2019-09-29
Posts: 106

Re: TSynQueue.Count

Thank you!

Offline

Board footer

Powered by FluxBB