Micro-threading
Sent here from Microthreading.
Introduction
There are some situations where applications need to execute lots of asynchronous concurrent operations. OS-level threads could be used for this purpose, but an application can create only a limited count of threads. As for CPU utilization there is no significant performance gain if more threads are created than physical cores available on a CPU. In fact threads could be used for parallel processing on a multi-core CPU and for writing more readable code. OS-level threads should be mainly used for parallelism and better CPU utilization. If a programmer needs to write code which will be called asynchronously, then OS-level threads will be rather expensive in perspective of system resources.
CPU context switching methods
- Cooperative (use of explicit Yield call)
- Preemptive (periodic timer based)
- Combined
Objectives
- Unlimited number of instances (limited by available memory)
- Fast switching, creation, destruction
- Automatic thread pool management by physical CPU core count
- Ability to run in main loop only (without TThread instances)
- Provide own synchronization tools (Yield, Sleep, CriticalSection, Semaphore, Mutex, WaitForMultipleObjects, Queues, Synchronize, ...)
- Priority control
- Support for view list of all microthreads
Implementations
- MicroThreading - Lazarus package, functional yet not finished, not multi-platform, needs patching the Free Pascal
- STAX - Single Threaded Asynchronous EXecution framework (STAX for short) enables async/await style co-routines for Free Pascal
External links
- C# Yield implementation in Delphi
- Cool little Coroutines function (Much better version)
- Fibers(Windows)
- MeSDK Delphi coroutine implementation
From the Free Pascal wiki, page "Micro-threading", as it stood on 2021-08-31 after a change by Alextpp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Edited on wiki.freepascal.org by 6 people, 2011–2021
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Chronos | New page: ==Introduction== There are some situations where applications needs to execute a lots of asynchronous concurrent operations. OS-level threads could be used for this purpose but applicatio... | |
| Chronos | ||
| Jwdietrich | ||
| Chronos | ||
| Arent | ||
| Arent | ||
| Chronos | ||
| Trev | Supported platforms (minor) | |
| Skalogryz | External links (minor) | |
| Skalogryz | External links (minor) | |
| Skalogryz | Implementation (minor) | |
| Skalogryz | External links (minor) | |
| Skalogryz | Implementation (minor) | |
| Alextpp | Introduction | |
| Alextpp | Alextpp moved page Microthreading to Micro-threading (minor) | |
| Alextpp | Supported platforms: this part relates to each package | |
| Alextpp | Implementation |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
