From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24263 invoked by alias); 10 Sep 2007 12:58:25 -0000 Received: (qmail 24253 invoked by uid 22791); 10 Sep 2007 12:58:23 -0000 X-Spam-Check-By: sourceware.org Received: from londo.lunn.ch (HELO londo.lunn.ch) (80.238.139.98) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 10 Sep 2007 12:58:19 +0000 Received: from lunn by londo.lunn.ch with local (Exim 3.36 #1 (Debian)) id 1IUiq9-0006IJ-00; Mon, 10 Sep 2007 14:58:09 +0200 Date: Mon, 10 Sep 2007 12:58:00 -0000 From: Andrew Lunn To: eCos@sunnorth.com.cn Cc: Andrew Lunn , ecos-discuss@ecos.sourceware.org Message-ID: <20070910125809.GA23980@lunn.ch> Mail-Followup-To: eCos@sunnorth.com.cn, Andrew Lunn , ecos-discuss@ecos.sourceware.org References: <20070910093526.GB20127@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-11) X-IsSubscribed: yes Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: [ECOS] Re: ????: Re: [ECOS] A problem about constructor sequence X-SW-Source: 2007-09/txt/msg00050.txt.bz2 On Mon, Sep 10, 2007 at 07:38:04PM +0800, eCos@sunnorth.com.cn wrote: > >I don't see how this can break anything. The scheduler is disabled at > >this point anyway. The the resume call just marks the thread as > >runable, but it won't get run until a lot later. > >Jifl: Is this O.K? > > Thanks a lot, really appreciate your answers. > > But I still doubt, I have checked the source code of thread.cxx, I found > that thread's state is set to SUSPENDED in Cyg_Thread class's constructor > and suspend_count variable is set to 1(1 represents suspended and 0 > represents ready or running, right?), so when Cyg_Thread's resume method > is called, suspend_count will be set to 0 to indicate this thread is not > suspended, and state of thread will be set, too. > > cyg_libc_main_thread is an instance of Cyg_Thread, so it must follow this > procedure. If it was constructed first, then when instance > cyg_libc_startup_obj is constructed, cyg_libc_main_thread.resume will be > called. > BUT if cyg_libc_main_thread is constructed after cyg_libc_startup_obj, I > think this case will cause problem. Because cyg_libc_startup_obj will call > cyg_libc_main_thread.resume, NOW I know scheduler is not start yet till > this point, so it just sets some flag, it is ok. > BUT after cyg_libc_startup_obj is constructed, then will be > cyg_libc_main_thread. In constructor of cyg_libc_main_thread, thread's > state will be set to SUSPENDED, and will never be resumed, isn't it? What i said was: > I think you are correct. Probably the second should be > > static cyg_libc_startup_dummy_constructor_class cyg_libc_startup_obj > CYGBLD_ATTRIB_INIT_AFTER(CYG_INIT_LIBC) The _AFTER() change means that cyg_libc_startup_obj is constructed after all other constructors of priority CYG_INIT_LIBC are called. Thus cyg_libc_main_thread will always be called first. Or am i missing something here? Andrew -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss