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 w开发者_C百科hat 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!
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.
精彩评论