yahns Ruby server user/dev discussion
 help / color / Atom feed
* [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	[flat|nested] only message in thread

only message in thread, back to index

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

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox