[fpc-pascal] Is TFPList thread safe?
Jonas Maebe
jonas.maebe at elis.ugent.be
Thu Oct 2 17:07:01 CEST 2014
On 02 Oct 2014, at 15:59, Xiangrong Fang wrote:
> I think the only thread-critical operation I need is to add item to
> the
> list, so I will use critical section myself, not replace TFPList with
> TThreadList, for simplicity and performance reason...
It will make your program unstable (adding an element to an fplist can
cause the entire internal array to move, so if you are in the middle
of a read operation at the same time, that read operation will either
read invalid data or crash). Unless you are an expert at multithreaded
programming, don't try to optimise existing thread-safe structures
(and definitely don't perform premature optimisations).
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141002/4ff6ff66/attachment.html>
More information about the fpc-pascal
mailing list