yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <yahns-public@yhbt.net>
To: yahns-public@yhbt.net
Subject: [PATCH] avoid Thread#[] and Thread#[]= across threads
Date: Fri, 24 Mar 2017 19:52:55 +0000	[thread overview]
Message-ID: <20170324195255.24309-1-yahns-public@yhbt.net> (raw)

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


                 reply	other threads:[~2017-03-24 19:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170324195255.24309-1-yahns-public@yhbt.net \
    --to=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://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).