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

ThreadPoolExecutor#kill: documentation and implementation are out of sync #1072

Open
hms opened this issue Nov 26, 2024 · 0 comments
Open

ThreadPoolExecutor#kill: documentation and implementation are out of sync #1072

hms opened this issue Nov 26, 2024 · 0 comments

Comments

@hms
Copy link

hms commented Nov 26, 2024

* Operating system:                mac
* Ruby implementation:             Ruby
* `concurrent-ruby` version:       1.3.4
* `concurrent-ruby-ext` installed: no
* `concurrent-ruby-edge` used:     no

The docs for ThreadPoolExecutor#kill suggest that inflight tasks will run to completion.

#kill

Begin an immediate shutdown. In-progress tasks will be allowed to complete but enqueued tasks will be dismissed and no new tasks will be accepted. Has no additional effect if the thread pool is not running.

This (maybe too) simple test suggests the Executor will kill its internal threads and not allow them to finish.

e = Concurrent::ThreadPoolExecutor.new
f = Concurrent::Promises.future_on(e) { sleep 10; puts "I'm alive!" }
sleep 11
I'm alive!
f = Concurrent::Promises.future_on(e) { sleep 10; puts "I'm alive!" }
e.kill
e.shutdown? => true
# future f never completes

The code for #kill in ruby_executor_service.rb:

def kill
  synchronize do
     break if shutdown?
     stop_event.set
     ns_kill_execution 
     stopped_event.set
   end
   true
 end

ns_kill_execution:

def ns_kill_execution
 # TODO log out unprocessed tasks in queue
 # TODO try to shutdown first?
 @pool.each(&:kill)
 @pool.clear
 @ready.clear
end

and @pool.each(&:kill) concludes with:

def kill
  @thread.kill
end
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

No branches or pull requests

1 participant