Quick Start
You can have a thread-safe list compiled and running in about five minutes. You need Free Pascal (fpc) on your PATH.
Five-minute first run#
The commands below compile the existing number-list example directly from source and keep all generated files under build-temp/.
Clone the repository:
git clone https://github.com/ikelaiah/threadsafecollections-fp.git
cd threadsafecollections-fpOn Windows PowerShell:
New-Item -ItemType Directory -Force build-temp\first-run\units, build-temp\first-run\bin | Out-Null
fpc -B -Fusrc -FUbuild-temp\first-run\units -FEbuild-temp\first-run\bin examples\SimpleNumberList\SimpleNumberList.lpr
.\build-temp\first-run\bin\SimpleNumberList.exeOn Linux with Bash:
mkdir -p build-temp/first-run/units build-temp/first-run/bin
fpc -B -Fusrc -FUbuild-temp/first-run/units -FEbuild-temp/first-run/bin examples/SimpleNumberList/SimpleNumberList.lpr
./build-temp/first-run/bin/SimpleNumberListThe program prints ten random integers, sorts them in both directions, and waits for Enter before exiting. The Windows commands and example were verified with FPC 3.2.2 on Win64. The same Bash build path is exercised for all examples by Linux CI. The maintained target platforms are Windows x86-64 and Linux; macOS is not currently targeted or tested.
Your first collection#
This complete program creates an integer list, adds values, sorts them, and prints the result:
program FirstThreadSafeList;
{$mode objfpc}{$H+}{$J-}
uses
ThreadSafeCollections.List;
var
Numbers: specialize TThreadSafeList<Integer>;
Number: Integer;
begin
Numbers := specialize TThreadSafeList<Integer>.Create(@IntegerComparer);
try
Numbers.AddRange([30, 10, 20]);
Numbers.Sort;
for Number in Numbers do
WriteLn(Number);
finally
Numbers.Free;
end;
end.Save it as build-temp/first-list/FirstThreadSafeList.lpr, then compile it with the same -Fusrc, -FU, and -FE pattern used in the first-build commands.
Expected output:
10
20
30Free Pascal orientation#
If Free Pascal generics are new to you, these are the conventions used by the library and its examples:
{$mode objfpc}selects the language mode used throughout this repository.usesimports units. Unit filenames and paths must keep their exact casing on
case-sensitive filesystems.
specializeturns a generic type such asTThreadSafeList<T>into a concrete
type such as TThreadSafeList<Integer>.
@IntegerComparerpasses the comparison function needed for list searching
and sorting. Custom element types need a comparer with the same signature.
- Classes are explicitly freed.
try..finallyensuresFreeruns if an
operation raises an exception.
- Interface-backed collections use reference counting instead; see
Lock tokens (RAII) and examples/InterfaceTest.
- A threaded Unix program should place
cthreadsfirst in its programuses
clause before it creates threads. The chat and benchmark examples demonstrate this pattern.
Next steps#
- Learning Path — the recommended example order.
- Installation — requirements and package setup.
- List guide — the full
TThreadSafeList<T>story.