Difference between revisions of "Micro-threading"

From Free Pascal wiki
Jump to navigationJump to search
(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...)
 
Line 33: Line 33:
  
  
[[Category:Multitasking]]
+
[[Category:Parallel programming]]

Revision as of 08:15, 2 February 2011

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 application can create only limited count of threads. In matter of CPU utilization there are no significant performance gain if more threads is created then physical cores CPU have. In fact threads could be used for parallel processing on multicore CPU and for writing more readable code. OS-level thread should be used mainly used for parallelism and better CPU utilization. If programmer needs to write code which will be called asynchronously than OS-level threads are rather expensive in perspective of system resource.


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


Implementation

External links