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

Threading fixes #1142

Closed
wants to merge 3 commits into from

Conversation

Projects
None yet
2 participants
@Smarre
Copy link

Smarre commented Oct 21, 2013

Hi,

First commit about list() should be ok as it is, atleast as far as I know.

The second one, I don’t really know the cause, or how this really affects, but it did get me a bit further. I’m having some strange threading related problems, which mostly are just due activerecord being not really multithreading compatible, but some strange NPEs and other errors too. So I decided to include this fix too.

Smarre added some commits Oct 21, 2013

RubyThreadGroup: make list() thread-safe.
If two different threads accesses list() at same time,
WeakHashMap.java:882:in `nextEntry': java.util.ConcurrentModificationException
happens.
Add a guard against nil RubyThreadGroup for a thread.
This is just here since I seem to get this error quite a bit.
I guess correct way would be to ensure somehow that there always
is the default group, but quick search didn’t give me any idea
how it can be missing in first place.
Ruby.java: make callEventHooks() thread-safe
It seems that concurrent calls to this method causes
Exception in thread "RubyThread-3: .." java.util.ConcurrentModificationException.
@Smarre

This comment has been minimized.

Copy link
Author

Smarre commented Oct 21, 2013

I added another synchronized function commit.

@headius

This comment has been minimized.

Copy link
Member

headius commented Oct 21, 2013

These are good fixes but I think I know some better ways to solve them without hard synchronization everywhere. I'll credit you for the finds, though.

headius added a commit that referenced this pull request Oct 21, 2013

Use COW list for event hooks, to avoid synchronization.
See #1142. This supercedes a fix there.

I opted to use CopyOnWriteArrayList here for two reasons:

* It does not require synchronization, neither for access nor iter
* EventHooks should are only added or removed rarely
@headius

This comment has been minimized.

Copy link
Member

headius commented Oct 21, 2013

I used your fix for RubyThreadGroup#list and the nil RubyThreadGroup issue and a different approach for the EventHooks list. Thank you!

@headius headius closed this Oct 21, 2013

@Smarre

This comment has been minimized.

Copy link
Author

Smarre commented Oct 21, 2013

No problems, better have better fixes :) Thanks for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.