El 03/10/2014 a las #4, Xiangrong Fang escribió:
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.
Hello,
You must protect with a CriticalSection, "Add" and any other kind of
access, like indexed access. As you must protect indexed access you are
in the same penalty as using TThreadList.
Threading example to a crash (numbers are execution steps):
Thread 1
--------
1-Resolve TList data access to $00010000
2-calculate item 23 is at $00010023
3-Read $00010023
4-Crash or read from unalocated memory (content undefined).
Thread 2
--------
1-Enter "Add" function and resolve Tlist data to $00010000
2-Lock thread and find that it need to relocate data to $00020000. Move data
3-Unlock
4-Continue
--
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal