Assume a multi-threaded environment and a (properly synchronized) class that has one particular procedure
procedure SortKeyList (KeyList : TList <Integer>; Inverted : Boolean);
that takes a list of keys and sorts it. The procedure uses the RTL quicksort implementation TList.Sort:
KeyList.Sort (TComparer <Integer>.Construct (CompareKeys))
Now for the problem: CompareKeys has to access some members of the class in order to sort the list (that's the whole point about this class). But the RTL requires CompareKeys to be a normal function. How can I pass data from the object to the CompareKeys function in a thread-safe manner? Obviously using global exchange variables isn't an option since it is in no way thread-safe.
Any ideas on that?