Fibers over Threads in D
Asked Answered
B

1

9

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!

Berberine answered 20/9, 2011 at 7:24 Comment(2)
This article does a very nice job of comparing the two. Getting more fiber in your diet.Samiel
Thanks, the article explains nicely!Berberine
R
8

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.

Refine answered 20/9, 2011 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.