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

Expound further on the behaviour of Mutex#sleep #342

Closed

Conversation

timabdulla
Copy link

The documentation for Mutex#sleep did not previously note that
after the thread that is put to sleep by the call to wait is woken
up, it will attempt to reacquire the mutex. This note has now been
added.

@zzak
Copy link
Member

zzak commented Jul 11, 2013

@timabdulla Thank you for your contribution!

The only spec on this I could find is here, which describes the mutex is relocked when woken up.

If your statement is true, I'd like to see a spec or example of this so that I can better understand your meaning. And if that works, it might be worth adding the bit about relock to the documentation as well.

@timabdulla
Copy link
Author

sorry, the commit message wasn't worded in the most precise manner. I was having difficulty trying to concisely explain the omission that I saw in the documentation. the spec that you've linked to demonstrates exactly the behaviour I was meaning to explain in my documentation addition. when a thread calls Mutex#sleep, the thread is put to sleep and the mutex released; upon being woken up for any reason, the thread will attempt to reacquire the mutex. I found that this behaviour was not clearly explained in the existing docs.

it's most easy to see the existence of this behaviour in the source[0], but I've also attached an example[1], though I think the rubyspec specs do a good job of illuming this behaviour.

[0] https://github.com/ruby/ruby/blob/trunk/thread.c#L4547-L4552
[1] https://gist.github.com/timabdulla/5977231

@zzak
Copy link
Member

zzak commented Jul 12, 2013

@timabdulla I think the confusion is the phrase "reacquire the mutex", but you should say "reacquire the lock".

I think it is easier to understand.

The documentation for Mutex#sleep did not previously
note that after the thread is woken up, it will attempt
to reacquire the lock. This note has now been added.
@timabdulla
Copy link
Author

@zzak cool, I agree. I modified the wording and updated the commit

@zzak
Copy link
Member

zzak commented Jul 13, 2013

@nurse @ko1 any objection?

@ko1
Copy link
Contributor

ko1 commented Jul 13, 2013

No objection.

@zzak zzak closed this in 89d8d76 Jul 15, 2013
tenderlove pushed a commit to tenderlove/ruby that referenced this pull request Jan 24, 2014
  By Tim Abdulla [Fixes rubyGH-342] ruby#342


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
jhawthorn pushed a commit to jhawthorn/ruby that referenced this pull request Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants