From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id A5B661B621EB for ; Mon, 3 Apr 2017 13:05:56 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 24BCBB5D86C for ; Mon, 3 Apr 2017 13:43:03 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 95B5C18D1D85 for ; Mon, 3 Apr 2017 13:43:03 +0900 (JST) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id DFDD7120702; Mon, 3 Apr 2017 13:43:01 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by neon.ruby-lang.org (Postfix) with ESMTPS id 0D5E21206B7 for ; Mon, 3 Apr 2017 13:42:56 +0900 (JST) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3E8A220966; Mon, 3 Apr 2017 04:42:54 +0000 (UTC) Date: Mon, 3 Apr 2017 04:42:54 +0000 From: Eric Wong To: ruby-core@ruby-lang.org Message-ID: <20170403044254.GA16328@starla> References: <20170402011414.AEA9B64CEE@svn.ruby-lang.org> <8a2b82e3-dc07-1945-55f9-5a474e89130b@ruby-lang.org> <20170402023514.GB30476@dcvr> <76459664-9857-4244-7d43-79b24e737efc@atdot.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <76459664-9857-4244-7d43-79b24e737efc@atdot.net> X-ML-Name: ruby-core X-Mail-Count: 80540 Subject: [ruby-core:80540] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" SASADA Koichi wrote: > On 2017/04/02 11:35, Eric Wong wrote: > > However, to spawn native threads: > > > > If a Thread uses existing GVL release C-API, then the _next_ > > Thread.new call will create a native thread (and future > > Thread.new will be subclass of Fiber in new native thread). > > > > So, in pseudo code: > > > > class Thread < Fiber > > def self.new > > case Thread.current[:gvl_state] > > when :none > > # default > > super # M += 1 > > when :released > > # this is set by BLOCKING_REGION GVL release > > # only allow a user-level thread to spawn one new native thread > > Thread.current[:gvl_state] = :spawned > > > > NativeThread.new { Thread.new } # N += 1 > > when :spawned > > # We already spawned on native thread from this user-level > > # thread, only spawn new user-level thread for now. > > super # M += 1 > > end > > end > > end > > > > Current GVL release operations will change > > Thread.current[:gvl_state] from :none -> :released > > Sorry I can't understand the basic of your idea with mixing Threads and > Fibers. Maybe you need to define more about the model. Sorry if I wasn't clear. Basically, I see: green Threads == Fibers + auto scheduling So, making Threads a subclass of Fibers makes sense to me. Then, existing (native) threads becomes an own internal class only accessible to C Ruby developers; new native threads get spawned as-needed (after GVL releases). > Our plan is not mixing Threads and Fibers, so that (hopefully) there are > no problem. OK, I will wait for you and see.