Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Task.yield and usage example #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

art-w
Copy link
Contributor

@art-w art-w commented Nov 28, 2022

(This PR is more of a question mark, there's an unpleasant change to make this POC work, and perhaps domainslib shouldn't provide this primitive?)

When using a lockfree datastructure to communicate between tasks, I didn't find a way to write the basic strategy "failed to make progress, retry later". With standard domains, we can use Domain.cpu_relax () to spinlock a bit... but with tasks this can deadlock the current domain (if we are waiting on a task scheduled on the same domain, we'll never give it a chance to run). Of course it (slowly) works if another domain steals our pending tasks, but all the domains may actually be stuck and unable to help.

I've included a small artificial example to demonstrate the issue :)

@@ -139,7 +139,7 @@ let rec recv_poll_loop mchan dls cur_offset =

let recv_poll_with_dls mchan dls =
try
Ws_deque.pop (Array.unsafe_get mchan.channels dls.id)
Ws_deque.steal (Array.unsafe_get mchan.channels dls.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ws_deque.pop returns the latest pushed item (like a stack ocaml-multicore/saturn#38 ), and as such doesn't allow yield to be run after we had a chance to go through the other tasks from the deque :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant