13
45
Fork
You've already forked fibers
10

How to run a fiber without waiting for its completion? #35

Open
opened 2020年03月01日 16:51:31 +01:00 by ZelphirKaltstahl · 2 comments
ZelphirKaltstahl commented 2020年03月01日 16:51:31 +01:00 (Migrated from github.com)
Copy link

Is there any way to run a fiber (it running its thunk), without resorting to something like call-with-new-thread? Perhaps something internal to the library?

What I want to achieve is to run a fiber without the overhead of creating a new thread, trusting, that the fiber will report a result itself later on, for example using an initially given channel. Having to use call-with-new-thread or similar defeats the purpose of lightweight fibers, when the number of fibers is not known at compile time and fibers are dynamically spawned, depending on data, that the program gets as input.

I want to be able to say: "OK, new work to do came in, just start a fiber and let it report the result of the work later, when it finished. Lets go on with other stuff we need to take care of." However, run-fibers returns, when the fibers in its thunk finish, so that is not a way to go. Also using multiple schedulers does not work, as they would not know about each other and their #:parallelism limits are independent, resulting in more parallelism than wanted.

I guess you could say, that I am looking for asynchronously starting fibers and getting their results.

Is there any way to run a fiber (it running its thunk), without resorting to something like `call-with-new-thread`? Perhaps something internal to the library? What I want to achieve is to run a fiber without the overhead of creating a new thread, trusting, that the fiber will report a result itself later on, for example using an initially given channel. Having to use `call-with-new-thread` or similar defeats the purpose of lightweight fibers, when the number of fibers is not known at compile time and fibers are dynamically spawned, depending on data, that the program gets as input. I want to be able to say: "OK, new work to do came in, just start a fiber and let it report the result of the work later, when it finished. Lets go on with other stuff we need to take care of." However, `run-fibers` returns, when the fibers in its thunk finish, so that is not a way to go. Also using multiple schedulers does not work, as they would not know about each other and their `#:parallelism` limits are independent, resulting in more parallelism than wanted. I guess you could say, that I am looking for asynchronously starting fibers and getting their results.
weinholt commented 2020年03月01日 17:09:36 +01:00 (Migrated from github.com)
Copy link

I might be missing something obvious, but is there a reason you don't run the whole program inside run-fibers? If you do then you can use spawn-fiber every time there is new work and then use channels as usual to get the results.

I might be missing something obvious, but is there a reason you don't run the whole program inside `run-fibers`? If you do then you can use `spawn-fiber` every time there is new work and then use channels as usual to get the results.
ZelphirKaltstahl commented 2020年03月01日 19:46:24 +01:00 (Migrated from github.com)
Copy link

@weinholt That is an interesting idea, to run the whole program in run-fibers.

I think the reason why I had not considered this is, that I want to abstract from the specific parallelism implementation (parallel forms, fibers, futures, other Scheme dialect's facilities, threads, ...), that the program uses, so that one can use the program in other Scheme dialects and change just a little part, the parallelism part, which ideally would be isolated in one procedure, which is called from the program.
I guess putting a run-fibers around the main program would also not be a lot to edit when porting to another Scheme dialect, but it would definitely require touching the main program, instead of something isolated to a single module or procedure.

@weinholt That is an interesting idea, to run the whole program in `run-fibers`. I think the reason why I had not considered this is, that I want to abstract from the specific parallelism implementation (parallel forms, fibers, futures, other Scheme dialect's facilities, threads, ...), that the program uses, so that one can use the program in other Scheme dialects and change just a little part, the parallelism part, which ideally would be isolated in one procedure, which is called from the program. I guess putting a `run-fibers` around the main program would also not be a lot to edit when porting to another Scheme dialect, but it would definitely require touching the main program, instead of something isolated to a single module or procedure.
Sign in to join this conversation.
No Branch/Tag specified
main
revert-110-wip-cancel-timer-operations
fdless-draft
pr-60-adjust
more-operations
timer-wheel
cross
nice-dynamic-wind-experiment
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.3.1
v1.3.0
v1.2.0
v1.1.1
v1.1.0
v1.0.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
guile/fibers#35
Reference in a new issue
guile/fibers
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?