From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Wong Cc: rainbows-talk@rubyforge.org Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: background threads Date: Mon, 18 Jun 2012 22:53:24 +0000 Message-ID: <20120618225324.GD3151@dcvr.yhbt.net> References: <4FDF7420.7030300@objectdata.com.br> <20120618215550.GA31162@dcvr.yhbt.net> <4FDF81A5.6080605@objectdata.com.br> <20120618224245.GA1830@dcvr.yhbt.net> <4FDF85C2.1030900@objectdata.com.br> Reply-To: Rainbows! list NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1340060031 21805 80.91.229.3 (18 Jun 2012 22:53:51 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 18 Jun 2012 22:53:51 +0000 (UTC) To: Alexandre Riveira Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Tue Jun 19 00:53:50 2012 Return-path: Envelope-to: gclrrg-rainbows-talk@m.gmane.org X-Original-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Delivered-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Resent-From: Eric Wong Resent-Date: Mon, 18 Jun 2012 22:53:43 +0000 Resent-Message-ID: <20120618225343.GE3151-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org> Resent-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham version=3.3.1 X-Original-To: normalperson-rMlxZR9MS24@public.gmane.org Content-Disposition: inline In-Reply-To: <4FDF85C2.1030900-VwDbj2YsoUp0ZRtCdD4y8VAUjnlXr6A1@public.gmane.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Rainbows! list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.rainbows.general:365 Archived-At: Received: from 50-56-192-79.static.cloud-ips.com ([50.56.192.79] helo=rubyforge.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SgkpQ-00048Y-Om for gclrrg-rainbows-talk@m.gmane.org; Tue, 19 Jun 2012 00:53:48 +0200 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 017B32E06E; Mon, 18 Jun 2012 22:53:47 +0000 (UTC) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 4AFC82E06D for ; Mon, 18 Jun 2012 22:53:44 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id D96E61F42D for ; Mon, 18 Jun 2012 22:53:43 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3107C1F42D; Mon, 18 Jun 2012 22:53:24 +0000 (UTC) Alexandre Riveira wrote: > Em 18-06-2012 22:42, Eric Wong escreveu: > >If you only want one background thread for all workers, it > >probably is best to just use a separate daemon independent of the > >Rainbows! server. > I want only one worker to run a background thread. I would like to > ensure that only one worker thread will be in the background. Sure > ... using rainbows :) It's a bad idea, I think... You can use process-shared locks Ruby provides File#flock. It's also possible to get fcntl()-based locking to work with pack(). Maybe there's extensions to share locks with multiple processes (e.g. POSIX semaphores, database-based locks in Redis/MySQL/Postgres). ...Or even use a really ugly method of using TCPServer to bind to a pre-determined port (and bailing on Errno::EADDRINUSE) (no need to accept connections on the TCPServer, just keep the object around so it doesn't get close(2)-ed on GC. But really, I think this type of background thread is a bad idea for Rainbows! (or any HTTP server). _______________________________________________ Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rainbows-talk Do not quote signatures (like this one) or top post when replying