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

Bounded queue #160

Merged
merged 19 commits into from
Nov 23, 2024
Merged

Bounded queue #160

merged 19 commits into from
Nov 23, 2024

Conversation

lyrm
Copy link
Collaborator

@lyrm lyrm commented Nov 15, 2024

Following PR #83, this PR adds a bounded queue but non-blocking (like in PR #83) to avoid adding Picos as a dependency to Saturn.

To do

  • Add examples in documentation and check with mdx
  • Debug the dscheck tests for unsafe version
  • Factorize code between unsafe/safe version
  • Add benchmarks
  • Qcheck tests : use the michael scott ones, and add some with capacity and for of_list
  • Add following functions (following Bounded stack #156 API):
    • is_full

Functions not added

  • pop_all is not an option as it is very likely to be too much work.
  • push_all : would create a lot of starvation and overhead if another thread move the tail before this operation is finished.
  • try_compare_and_pop, try_compare_and_push, set_exn etc.. : for a future PR is a good use of these functions is found.

@lyrm lyrm marked this pull request as draft November 15, 2024 16:15
@lyrm lyrm marked this pull request as ready for review November 15, 2024 17:39
@lyrm
Copy link
Collaborator Author

lyrm commented Nov 17, 2024

This PR is nearly complete, but there are a few points to address:

  1. Should we keep the current name, Cue?

    • Pros: It’s short and easy to remember.
    • Cons: It may not be very descriptive or expressive.
  2. The performance of the safe version is bad. Should I add a note about this in the documentation?

    • I plan to open an issue discussing this, suggesting that we consider using the two-stack queue from Picos as the base for the bounded queue, instead of the Michael-Scott queue (as proposed by @polytypic).

Copy link
Contributor

@art-w art-w left a comment

Choose a reason for hiding this comment

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

This looks very good! I'm curious if the memory cost of the counter/capacity fields is worth the reduced contention on a shared Atomic? But at the same time, I'm in awe with how smart that technique is :) ... Perhaps one thing to consider (document?) is that TSan users will get "false" data-race reports that they will need to silence ( https://ocaml.org/manual/5.2/tsan.html#s:tsan-runtime-flags )

  1. I agree that Cue is a cute name, but that Bounded_queue or Queue_bounded would be more appropriate
  2. I think it's expected that the _unsafe variant will be faster with no special need to document it

@lyrm lyrm merged commit 471912c into ocaml-multicore:main Nov 23, 2024
6 checks passed
@lyrm lyrm mentioned this pull request Nov 23, 2024
9 tasks
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.

2 participants