Skip to content

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

Merged
merged 19 commits into from
Aug 19, 2015

Conversation

ryblovAV
Copy link
Contributor

added answer to exercise 3-10 ch.2
@axel22 pls see this answers

@axel22
Copy link
Member

axel22 commented Aug 18, 2015

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
Copy link
Member

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.

@axel22
Copy link
Member

axel22 commented Aug 18, 2015

Looks good overall - the major points are with synchronizing isEmpty and nonEmpty in sync-var exercises, and with the sendAll implementation.

Please address my comments, and I'll merge this in - and thanks a lot again!

@ryblovAV
Copy link
Contributor Author

@axel22 thanks for the detailed reply, I will try to address your comments

@ryblovAV
Copy link
Contributor Author

@axel22 pls see this changes


def getWait():T = this.synchronized {
while (syncQueue.isEmpty) {
this.notify
Copy link
Member

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.

@axel22
Copy link
Member

axel22 commented Aug 19, 2015

@ryblovAV Thanks for the changes! I only left one last remark.

@axel22
Copy link
Member

axel22 commented Aug 19, 2015

Actually, I can also merge this in, and then personally do the change.

axel22 added a commit that referenced this pull request Aug 19, 2015
Answer to exercise 3-10 ch.2
@axel22 axel22 merged commit e06fcbf into concurrent-programming-in-scala:master Aug 19, 2015
@axel22
Copy link
Member

axel22 commented Aug 19, 2015

Awesome work!

@ryblovAV
Copy link
Contributor Author

Thanks!

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