|
Threads are 'lightweight' processes:
|
| • | They share their code, heap, static and external data memory with all the other threads created by the same task; |
|
|
| • | They can share data and may communicate either via shared memory and semaphores or by using channels; |
|
|
| • | All the threads of a single task run on the same processor, allowing them to share memory. |
|
Tasks on the other hand are more substantial:
|
| • | They communicate only via channels; |
|
|
| • | Each task has its own code and data areas, separate from all other tasks; code, including run-time library functions, is not shared between tasks, even by identical tasks placed on the same processor; |
|
|
| • | A task can be moved to a different processor simply by reconfiguration. |
|
Two operations to be performed concurrently can be usefully performed by threads rather than tasks if all of the following conditions hold:
|
| • | They will never need to be run on distinct processors; |
|
|
| • | The operations are closely coupled, i.e., they share a lot of common code. Code is automatically shared between threads, but each task has its own copy of all of its code, including library functions, so that if necessary it can later be moved to a different processor without requiring recompilation or re-linking; |
|
|
| • | The operations logically operate on shared data structures. This may be more efficiently performed directly by concurrent threads than by tasks copying the data back and forth as messages when they are modified. |
|
|