How can I implement a thread-safe list wrapper in Delphi?

I have a list wrapper that maintains two Tstringlists and a TClassList

I need this to be thread safe, such that:

  • Concurrent writes are not allowed (wait state of some sort should be entered)
  • Reading while writing (or vice versa) is not allowed (wait state of some sort should be entered)
  • Concurrent reads are allowed

Any ideas on how I can do this? My instinct tells me it needs more than just a critical section, perhaps a semaphore or "usage counter", perhaps one of these in conjunction with a CS.

I'm just not quite sure where to start - anything from an overall approach in english to psuedo-code, to delphi implementation or external link would be much appreciated.

Answers


You should have a look at the TMultiReadExclusiveWriteSynchronizer class declared in sysutils.pas...


Need Your Help

Convert numpy.ndarray to list (Python)

python numpy arcpy

I am running a function developed by Esri to get list of values in a integer column of a spatial table (however, the same behaviour is observed even when running the function on a non-spatial table).

Tuple index out of range Tkinter

graph indexing plot tkinter tuples

So I've got a program that should take a function as input and graph it on a Tkinter canvas.