D 中的线程之上的纤维
我正在试验 D 中的线程和纤程,我想知道是否可以在主线程运行时在不同的 CPU 上运行纤程。如果情况并非如此,那么使用光纤而不是线程的原因是什么? (非常欢迎实际例子)
我尝试用 Fibers 编写一些初始程序,在一段时间后我切换到下一个 Fibers。然而我注意到CPU使用率只停留在一个CPU上。
D 的文档指出:
请注意,不要求光纤必须绑定到一个 特定线程。相反,纤维可以在螺纹之间自由通过 只要它们当前没有执行。
这是否意味着如果我希望光纤使用不同的 CPU,我必须提供一个线程供光纤运行?如果是这样的话,我就看不出这样做的目的了。
提前致谢!
I'm experimenting with threads and Fibers in D and I was wondering if it is possible to run a Fiber on a different CPU as the main thread is running. And if this is not the case then what would be the reason of using Fibers over Threads. (Practical examples are very welcome)
I tried to write some initial program with Fibers where I switch to the next fiber after some time. Howhever I noticed that the cpu usage stays only on one cpu.
The documentation of D states:
Please note that there is no requirement that a fiber be bound to one
specific thread. Rather, fibers may be freely passed between threads
so long as they are not currently executing.
Does this mean that I have to provide a thread for the fiber to run on if i want it to use a different CPU ? If this is the case then I don't see the purpose.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
纤维是一种用于协作多任务处理的轻量级机制,并且与其创建者/调用者在同一线程中运行。如果需要在不同的 CPU 上运行任务,请使用线程。纤程的目的是提供快速协作上下文切换和实现协程等模式的机制。
Fibers are a lightweight mechanism for cooperative multitasking, and run in the same thread as their creator / caller. If you need to run a task on a different CPU, use threads. The purpose of fibers is to provide fast cooperative context switching and mechanisms for implementing patterns such as coroutines.