I have read that cloned TClientDataSets are thread safe if the clones are read only (no posting of records or reloading of data)
Delphi - Is TClientDataset Thread Safe?
But I'm concerned about the CloneCursor method itself; the method ends by calling the source DataSet's SetNotifyCallback method, which passes a callback method to it's IDSCursor if FNotifyCallback is False:
procedure TCustomClientDataSet.SetNotifyCallback;
begin
if not FNotifyCallback then
begin
Check(FDSCursor.SetNotifyCallBack(IntPtr(Self), @TCustomClientDataSet.NotifyCallback));
FNotifyCallback := True;
end;
end;
In the unlikely event of two DataSets, A & B, in separate threads cloning to DataSet C at almost the same time (DataSet C's FNotifyCallback False), with A fractionally ahead of B. B starts executing C's SetNotifyCallBack after A has checked FNotifyCallback but before A has set FNotifyCallBack to True in the method shown above.
In this scenario, DataSet C's FDSCursor SetNotifyCallback method is being called almost simultaneously by two different threads; a method that is writing a reference to a variable inside IDSCursor (I assume; no luck finding source code). Admittedly both calls are asking the same reference to be stored, but as the title asks, is CloneCursor thread-safe?
Please accept my thanks in advance.