[fpc-pascal] Is TFPList thread safe?

Xiangrong Fang xrfang at gmail.com
Fri Oct 3 00:47:33 CEST 2014


2014-10-02 23:07 GMT+08:00 Jonas Maebe <jonas.maebe at elis.ugent.be>:

>
> On 02 Oct 2014, at 15:59, Xiangrong Fang wrote:
>
> 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).
>
> I don't intend to do any optimization. I just think that I need to enter a
critical section, add item to the list, then leave the critical section.

I am definitely not expert in thread programming, but I am clear about the
logic of my class and program.   Actually, it is a TTree object I wrote,
using TFPList to store sibling nodes. There are a lot of TFPList (one per
tree node).   I just need to make sure that there are no more than one
thread operating on the same node at the same time.

Xiangrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141003/c06efdb8/attachment.html>


More information about the fpc-pascal mailing list