-
Notifications
You must be signed in to change notification settings - Fork 105
Answer to exercise 3-10 ch.2 #15
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
Answer to exercise 3-10 ch.2 #15
Conversation
Thanks a lot for your contribution! I'll leave a couple of comments before merging this in. |
def get(): T = this.synchronized { | ||
if (empty) throw new Exception("must be non-empty") | ||
else { | ||
empty = true |
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.
Nit: here you might want to set x
back to null
, to avoid a potential memory leak.
Looks good overall - the major points are with synchronizing Please address my comments, and I'll merge this in - and thanks a lot again! |
@axel22 thanks for the detailed reply, I will try to address your comments |
@axel22 pls see this changes |
|
||
def getWait():T = this.synchronized { | ||
while (syncQueue.isEmpty) { | ||
this.notify |
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 did not run this, but it still seems to me that this notify
is not necessary.
The notify
should occur only when the state of the queue changes in such a way that it could allow some other thread to progress. Here, the isEmpty
does not change the state of the queue in any way, so whichever thread waited as a result of some condition, will see the queue in the same state after it wakes up.
@ryblovAV Thanks for the changes! I only left one last remark. |
Actually, I can also merge this in, and then personally do the change. |
Awesome work! |
Thanks! |
added answer to exercise 3-10 ch.2
@axel22 pls see this answers