Micro-threading: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Micro-threading
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Introduction | |
| 2 | + | ||
| 3 | + | 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. | |
| 4 | + | ||
| 5 | + | ### CPU context switching methods | |
| 6 | + | ||
| 7 | + | - Cooperative (use of explicit [[Yield]] call) | |
| 8 | + | - Preemptive (periodic timer based) | |
| 9 | + | - Combined | |
| 10 | + | ||
| 11 | + | ### Objectives | |
| 12 | + | ||
| 13 | + | - Unlimited number of instances (limited by available memory) | |
| 14 | + | - Fast switching, creation, destruction | |
| 15 | + | - Automatic thread pool management by physical CPU core count | |
| 16 | + | - Ability to run in main loop only (without [[TThread]] instances) | |
| 17 | + | - Provide own synchronization tools (Yield, Sleep, CriticalSection, Semaphore, Mutex, WaitForMultipleObjects, Queues, Synchronize, ...) | |
| 18 | + | - Priority control | |
| 19 | + | - Support for view list of all microthreads | |
| 20 | + | ||
| 21 | + | ## Implementations | |
| 22 | + | ||
| 23 | + | - [MicroThreading](http://svn.zdechov.net/PascalClassLibrary/MicroThreading/) - Lazarus package, functional yet not finished, not multi-platform, needs patching the Free Pascal | |
| 24 | + | - [[STAX]] - Single Threaded Asynchronous EXecution framework (STAX for short) enables async/await style co-routines for Free Pascal | |
| 25 | + | ||
| 26 | + | ## External links | |
| 27 | + | ||
| 28 | + | - [C# Yield implementation in Delphi](http://santonov.blogspot.com/2007/10/yield-you.html) | |
| 29 | + | - [Cool little Coroutines function (Much better version)](http://www.festra.com/wwwboard/messages/12899.html) | |
| 30 | + | - [Fibers(Windows)](http://msdn.microsoft.com/en-us/library/ms682661%28v=vs.85%29.aspx) | |
| 31 | + | - [MeSDK Delphi coroutine implementation](https://code.google.com/p/meaop/source/browse/trunk/MeObjects/src/uMeCoroutine.pas) | |
| 32 | + | ||
| 33 | + | --- | |
| 34 | + | *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](/wiki-contact).* | |
| 35 | + | Category: Multitasking | |
| 36 | + | Category: Parallel programming |
