Threads
Scheme supports multiple threads of evaluation. Threads run concurrently, in the sense that one thread can preempt
another without its cooperation, but threads currently all run on the same processor (i.e., the same underlying OS process
and thread).
Threads are created explicitly by functions such as thread. In terms of the evaluation model, each step in evaluation
actually consists of multiple concurrent expressions, up to one per thread, rather than a single expression. The expressions
all share the same objects and top-level variables, so that they can communicate through shared state. Most evaluation steps
involve a single step in a single expression, but certain synchronization primitives require multiple threads to progress
together in one step.
In addition to the state that is shared among all threads, each thread has its own private state that is accessed through
thread cells. A thread cell is similar to a normal mutable object, but a change to the value inside a thread cell is seen only
when extracting a value from the cell from the same thread. A thread cell can be preserved; when a new thread is created,
the creating thread's value for a preserved thread cell serves as the initial value for the cell in the created thread.
For a non-preserved thread cell, a new thread sees the same initial value (specified when the thread cell is created) as
all other threads.
July 7th Tuesday (七月 七日 火曜日)
最新推荐文章于 2025-08-21 09:06:15 发布
本文介绍了Scheme语言中多线程的支持方式,包括线程如何并发运行、评价模型中的表达式如何分配到各个线程、线程间如何通过共享状态进行通信等。此外还讨论了线程细胞的概念及其在不同线程间的可见性问题。
1335

被折叠的 条评论
为什么被折叠?



