Chapter 36 Further Reading
Official Documentation
- Free Pascal TThread Reference — Complete documentation for the TThread class, including all properties and methods.
-
https://www.freepascal.org/docs-html/rtl/classes/tthread.html
-
Free Pascal SyncObjs Unit — Documentation for TCriticalSection, TEvent, and other synchronization primitives.
-
https://www.freepascal.org/docs-html/rtl/syncobjs/index.html
-
Lazarus Wiki: Multithreaded Application Tutorial — Step-by-step guide to threading in Lazarus GUI applications, including common patterns and pitfalls.
- https://wiki.lazarus-ide.org/Multithreaded_Application_Tutorial
Books
-
Herlihy, M. and Shavit, N. (2012). The Art of Multiprocessor Programming. The definitive textbook on concurrent data structures and algorithms. Covers lock-free programming, concurrent queues, and correctness proofs.
-
Goetz, B. et al. (2006). Java Concurrency in Practice. Despite being Java-focused, this is one of the best explanations of concurrent programming concepts (visibility, atomicity, ordering) that apply to any language.
-
Butenhof, D.R. (1997). Programming with POSIX Threads. The classic reference on pthreads. Pascal's TThread is built on pthreads (on Unix) and Windows threads (on Windows), so understanding the underlying model is valuable.
Connecting to Other Languages
| Concept | Pascal | Java | Python | Go | Rust |
|---|---|---|---|---|---|
| Thread class | TThread |
Thread |
threading.Thread |
goroutine | std::thread |
| Mutex | TCriticalSection |
synchronized / ReentrantLock |
threading.Lock |
sync.Mutex |
Mutex<T> |
| GUI update | Synchronize / Queue |
SwingUtilities.invokeLater |
after_idle (Tk) |
N/A | N/A |
| Thread pool | Custom | ExecutorService |
ThreadPoolExecutor |
goroutines + channels | rayon crate |
The threading concepts (mutual exclusion, race conditions, deadlocks) are identical across all languages. Only the syntax and API names change.
Advanced Topics (Beyond This Chapter)
- Lock-free programming: Using atomic operations (InterlockedIncrement, CompareAndSwap) instead of locks. Faster but much harder to get right.
- Condition variables (TEvent): Allow threads to wait for a specific condition, more efficient than polling.
- Read-write locks: Allow multiple simultaneous readers but exclusive writers. Useful when reads far outnumber writes.
- Futures and promises: A pattern where a thread returns a "future" object that will eventually contain the result. Common in modern languages but can be implemented in Pascal.