Correctly implement Thread#kill #1882

Merged
merged 3 commits into from Sep 27, 2012

Conversation

Projects
None yet
3 participants
Member

ryoqun commented Sep 2, 2012

Re-implement Thread#kill by adding new RaiseReason rather than complicating the
existing ad-hoc way of raising Exceptions.

Conceputually, Thread#kill isn't quite like exceptions. If the exception approach
wasn't replaced, it would be neccesary to really specially handle Thread::Die.

Make some failing specs pass. Also, Fix #864.

This pull request fails (merged b39c19ad into 149a364).

This pull request passes (merged 8dbf02a4 into 149a364).

@dbussink dbussink commented on an outdated diff Sep 2, 2012

vm/builtin/thread.cpp
@@ -309,6 +309,29 @@ static intptr_t thread_debug_id(pthread_t thr) {
return exc;
}
+ Object* Thread::kill(STATE, GCToken gct) {
+ init_lock_.lock();
@dbussink

dbussink Sep 2, 2012

Owner

Looks like we could use a lockguard here, since we lock at the beginning of the method and only unlock right before returning. If you look at Thread::context, you see it being used this.

This probably applies for Thread::wakeup and Thread::raise as well.

@dbussink dbussink commented on an outdated diff Sep 2, 2012

kernel/bootstrap/thread18.rb
end
+ def kill
+ @dying = true
+ if @sleep and @killed
+ @sleep = false
+ wakeup
+ else
+ @sleep = false
+ @killed = true
+ kill_prim
+ end
+ end
@dbussink

dbussink Sep 2, 2012

Owner

Did you try to reason about this method under concurrent scenario's? I wonder what the behavior should be when for example multiple other threads try to kill the same thread, can that for example result in the thread not being killed at all? Should we use a lock here or not?

@dbussink dbussink commented on an outdated diff Sep 2, 2012

vm/vm.hpp
@@ -407,6 +408,7 @@
}
void register_raise(STATE, Exception* exc);
+ void trigger_kill(STATE);
@dbussink

dbussink Sep 2, 2012

Owner

Curious, what's the reason here for the different naming, trigger_kill instead of register_kill?

Owner

dbussink commented Sep 15, 2012

Are the comments I made here useful? We should probably merge this, I can also address the issue after merging if you want, but want to keep it going forward :).

Member

ryoqun commented Sep 15, 2012

@dbussink Yes, your comments are useful. I was just working on other thread-related pull requests. If the thread raise deadlock is merged in, I want to and will merge this as a next step. :D

Owner

dbussink commented Sep 27, 2012

Ok, merged the deadlock related code. Are there any changes that need to be made here before we can merge this?

Member

ryoqun commented Sep 27, 2012

Working on updating this pull request.

ryoqun added some commits Sep 3, 2012

@ryoqun ryoqun Use LockGuards where appropriate as RAII 27e3de4
@ryoqun ryoqun Correctly implement Thread#kill
Re-implement Thread#kill by adding new RaiseReason rather than complicating the
existing ad-hoc way of raising Exceptions.

Conceputually, Thread#kill isn't quite like exceptions. If the exception approach
wasn't replaced, it would be neccesary to really specially handle Thread::Die.

Make some failing specs pass. Also, Fix #864.
ba7667b
@ryoqun ryoqun Implement 1.8 specific Thread#kill behavior 523f136

dbussink merged commit d8f1f0e into rubinius:master Sep 27, 2012

1 check failed

default The Travis build failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment