-
Notifications
You must be signed in to change notification settings - Fork 603
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
Reimplement PipedInput/OutputStream #2383
Conversation
The failing tests are already addressed in #2373. |
* | ||
* @param capacity the capacity of the allocated circular buffer | ||
*/ | ||
private[io] final class InputOutputBuffer(private[this] val capacity: Int) { self => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One general question: given that this entire class only depends on Java libraries, could it be submitted for the Scala standard library? Sys or process.
private[this] var closed: Boolean = false | ||
|
||
private[this] val readerPermit: Semaphore = new Semaphore(1) | ||
private[this] val writerPermit: Semaphore = new Semaphore(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a summary of how these permits are used? Are their values ever > 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe they can be > 1 at some point, they are not completely foolproof, they are just here to prevent threads from looping endlessly when there is nothing to be read from the buffer. This is fine, because there is one more monitor, the self.synchronized
block, which actually guards the critical section. Does this make any sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay cool. My only concern is that some strange access pattern could result in writerPermit
getting very large, which then causes lots of looping when waiting to write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's not rush this, I will reiterate on the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented a custom synchronizer that allows at most 1 permit at any time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Wow the |
Resolves #2037. I included the original reproduction as a test.
This was not pleasant to write.