* [PATCH] avoid Thread#[] and Thread#[]= across threads
@ 2017-03-24 19:52 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-03-24 19:52 UTC (permalink / raw)
To: yahns-public
Support for it may be removed in future versions of Ruby(*),
and we actually do not need to waste time looping when
a instance variable will do.
(*) https://bugs.ruby-lang.org/issues/13245
---
lib/yahns/acceptor.rb | 6 +++---
lib/yahns/server.rb | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/yahns/acceptor.rb b/lib/yahns/acceptor.rb
index 7ab9f60..7340a1a 100644
--- a/lib/yahns/acceptor.rb
+++ b/lib/yahns/acceptor.rb
@@ -24,7 +24,7 @@ def ac_quit
close
return true
end
- @thrs.each { |t| t[:yahns_quit] = true }
+ @quit = true
return true if __ac_quit_done?
@thrs.each do
@@ -42,10 +42,10 @@ def ac_quit
end
def spawn_acceptor(nr, logger, client_class)
+ @quit = false
@thrs = nr.times.map do
Thread.new do
queue = client_class.queue
- t = Thread.current
accept_flags = Kgio::SOCK_NONBLOCK | Kgio::SOCK_CLOEXEC
qev_flags = client_class.superclass::QEV_FLAGS
begin
@@ -64,7 +64,7 @@ def spawn_acceptor(nr, logger, client_class)
sleep 1 # let other threads do some work
rescue => e
Yahns::Log.exception(logger, "accept loop", e)
- end until t[:yahns_quit]
+ end until @quit
end
end
end
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb
index 00e5f15..861b919 100644
--- a/lib/yahns/server.rb
+++ b/lib/yahns/server.rb
@@ -451,7 +451,7 @@ def quit_finish
@queues.each(&:close).clear
# we must not let quitter get GC-ed if we have any worker threads leftover
- @wthr.each { |t| t[:yahns_quitter] = quitter }
+ @quitter = quitter
quitter.close
rescue => e
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-03-24 19:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-24 19:52 [PATCH] avoid Thread#[] and Thread#[]= across threads Eric Wong
Code repositories for project(s) associated with this public inbox
http://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).