Skip to content

Commit

Permalink
Fix Process.detach thread behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed May 7, 2012
1 parent ba0c103 commit 213d862
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
21 changes: 0 additions & 21 deletions kernel/common/process.rb
Expand Up @@ -376,27 +376,6 @@ class << self
alias_method :waitpid2, :wait2
end

#
# Indicate disinterest in child process.
#
# Sets up an internal wait on the given process ID.
# Only possibly real pids, i.e. positive numbers,
# may be waited for.
#
# TODO: Should an error be raised on ECHILD? --rue
#
# TODO: This operates on the assumption that waiting on
# the event consumes very little resources. If this
# is not the case, the check should be made WNOHANG
# and called periodically.
#
def self.detach(pid)
raise ArgumentError, "Only positive pids may be detached" unless pid > 0

# The evented system does not need a loop
Thread.new { Process.wait pid }
end

#--
# TODO: Most of the fields aren't implemented yet.
# TODO: Also, these objects should only need to be constructed by
Expand Down
14 changes: 14 additions & 0 deletions kernel/common/process18.rb
Expand Up @@ -25,6 +25,20 @@ def self.exec(cmd, *args)
Process.perform_exec prog, argv
end
end

# TODO: Should an error be raised on ECHILD? --rue
#
# TODO: This operates on the assumption that waiting on
# the event consumes very little resources. If this
# is not the case, the check should be made WNOHANG
# and called periodically.
#
def self.detach(pid)
raise ArgumentError, "Only positive pids may be detached" unless pid > 0

# The evented system does not need a loop
Thread.new { Process.wait pid; $? }
end
end

module Kernel
Expand Down
17 changes: 17 additions & 0 deletions kernel/common/process19.rb
Expand Up @@ -289,6 +289,23 @@ def self.spawn(*args)
pid
end
end

# TODO: Should an error be raised on ECHILD? --rue
#
# TODO: This operates on the assumption that waiting on
# the event consumes very little resources. If this
# is not the case, the check should be made WNOHANG
# and called periodically.
#
def self.detach(pid)
raise ArgumentError, "Only positive pids may be detached" unless pid > 0

thread = Thread.new { Process.wait pid; $? }
thread[:pid] = pid
def thread.pid; self[:pid] end

thread
end
end

module Kernel
Expand Down

0 comments on commit 213d862

Please sign in to comment.