Browse files

Fix Process.detach thread behavior

  • Loading branch information...
1 parent ba0c103 commit 213d862722ed77cdc933bb50ae76bbe39ff65962 @jfirebaugh jfirebaugh committed May 7, 2012
Showing with 31 additions and 21 deletions.
  1. +0 −21 kernel/common/process.rb
  2. +14 −0 kernel/common/process18.rb
  3. +17 −0 kernel/common/process19.rb
View
21 kernel/common/process.rb
@@ -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
View
14 kernel/common/process18.rb
@@ -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
View
17 kernel/common/process19.rb
@@ -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

0 comments on commit 213d862

Please sign in to comment.