-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement and export
isfull
(#53159)
This PR implements `isfull(c::Channel)`. It calls `n_avail(c) ≥ c.sz_max` in all cases. The original implementation was inspired by [this comment](https://discourse.julialang.org/t/function-to-check-if-channel-is-full/44795/3?u=thelatekronos), and therefore had a special case for unbuffered channels, which fell back to `isready`. I opted against this behaviour, because it fails to respect that an unbuffered channel is always full, in two important senses: 1) The number of elements available is greater than or equal the capacity 2) A call to `put!` will block With the current implementation, the behaviour is simply understood and summarized in all cases by the start of the docstring: > Determines whether a `Channel` is full, in the sense that calling `put!(c, some_value)` will block. Shoutout to @SamuraiAku for their work in #40720, which helped me a lot on thinking this through, and remembering to change all relevant files. In particular, the detail around how `c.cond_take.waitq` may result in immediate unblocking, which is a really important caveat on a function that may be used to check if `put!`ing will block. However, for buffered channels, `isfull` is extremely close to `putwillblock` from #40720 (just a little better, with >= instead of ==), and for unbuffered channels it does not make much sense to see if `put!`ing will block. This PR is created based on [this](#22863 (comment)) "call to action". Checklist: - [x] Entry in news - [x] Docstring with example - [x] Export function - [x] Mention in manual - [x] Entry in [docs-reference](https://docs.julialang.org/en/v1/base/parallel/) --------- Co-authored-by: Jameson Nash <vtjnash@gmail.com>
- Loading branch information
1 parent
962bbf7
commit c06662a
Showing
6 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -719,6 +719,7 @@ export | |
# channels | ||
take!, | ||
put!, | ||
isfull, | ||
isready, | ||
fetch, | ||
bind, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters