This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: ????: Re: A problem about constructor sequence
- From: Andrew Lunn <andrew at lunn dot ch>
- To: eCos at sunnorth dot com dot cn
- Cc: Andrew Lunn <andrew at lunn dot ch>, ecos-discuss at ecos dot sourceware dot org
- Date: Mon, 10 Sep 2007 14:58:09 +0200
- Subject: [ECOS] Re: ????: Re: [ECOS] A problem about constructor sequence
- References: <20070910093526.GB20127@lunn.ch> <OFD56A862C.7D2739A1-ON48257352.003F8CFF-48257352.003FE916@sunnorth.com.cn>
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