Threadsafe access of FIFO from 2 separate threads in Delphi
Posted on 2014-07-11
I have an application where it is necessary to build and fill a FIFO style queue. There is a Thread that is responsible for polling a client machine for data. This data needs to be pumped into a queue. Then, asynchronously, the main thread is going to retrieve data from the queue for processing.
What is the best way to make this threadsafe? Two separate threads need to access the same queue (there are other properties they both need to access as well; such as a channel count, etc). The producer (filling) thread will be running in a continuous loop. The consumer (dumper) will be executed asynchronous to the fill and I have no control over when it is called (it is external to my section of code).
This may be very simple, but I am new to Delphi. I have read about synchronizing, but I would love to see an example that shows this or something near. I do not need assistance on setting up a queue unless there is an issue with using TObjectQueue.
Thanks in advance!