Skip to content

Event potential concurrency issues #5

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 2 commits into from
Jan 20, 2014
Merged

Event potential concurrency issues #5

merged 2 commits into from
Jan 20, 2014

Conversation

mighe
Copy link
Contributor

@mighe mighe commented Jan 18, 2014

Event class has some potential concurrency issues.
Event#set? was not synchronized, causing inconsistent visibility under happens-before based memory model (like JRuby and Rubinius)
Event#wait was using an array to store enqueued threads and Event#set woke up them: a ConditionVariable is best suited in those cases and solves some check-then-act issues of the original version

All test are still passing

mighe added 2 commits January 18, 2014 18:19
Event#wait policy changed with a ConditionVariable
Event#set and Event#reset changed to support the new policy
Event general refactor
…by thread that posted them

added: ImmediateExecutor specs
future_spec, context fulfillment, changed to use ImmediateExecutor, so it can run faster
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 892bf83 on mighe:master into fffd747 on jdantonio:master.

@mighe
Copy link
Contributor Author

mighe commented Jan 19, 2014

I made a noob mistake, the second commit was for another pull request...
I've started to refactor a little tests to make them faster, avoiding multithreading when it's not necessary

@jdantonio
Copy link
Member

I apologize for not looking at this pull request earlier. The past several days have been very busy both at home and at work. I greatly appreciate your help. I don't entirely follow your last comment. Is this PR ready to go or are you still working on the refactoring?

@mighe
Copy link
Contributor Author

mighe commented Jan 20, 2014

This PR is ready, in the next days I'm going to improve some other classes and refactor some other tests.
I prefer to commit immediately this first test refactor to allow everyone to contribute.

@mutex.synchronize do
return true if @set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I expected this to raise a LocalJumpError, which is the normal case when using return within a block. But I've tried it in several version of MRI and it works. So I've learned a new trick with Mutex.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think return always works when there's a method context somewhere up in the stack.

@jdantonio
Copy link
Member

Thank you for the time and effort you have spent on this. The reason I didn't synchronize the @set variable in the places you noted is that I expected the access to be atomic and not in need of locking. You'll find that idiom used in several places in the gem. I'll make sure to fix them as I find them.

jdantonio added a commit that referenced this pull request Jan 20, 2014
Event potential concurrency issues
@jdantonio jdantonio merged commit 464b1a6 into ruby-concurrency:master Jan 20, 2014
adamruzicka added a commit to adamruzicka/concurrent-ruby that referenced this pull request Dec 11, 2014
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.

3 participants