This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Some bugs in ECOS kernel



-----Original Message-----
From: Jonathan Larmour [mailto:jifl@eCosCentric.com]
Sent: Thursday, March 04, 2004 5:55 AM
To: Кондратенко Антон Александров
Cc: ecos-discuss@sources.redhat.com; Nick Garnett
Subject: Re: [ECOS] Some bugs in ECOS kernel


Thanks you Jonathan for your explanation, but I still have some incomprehension.


> 2.
> see "packages\kernel\current\src\common\thread.cxx"
> Function Cyg_Thread::kill(), didn't check a state of thread before check "sleep_reason". So if thread is running but "sleep_reason" not NONE (whereas after last sleeping sleep_reason not resetting to NONE), kill() will not really kill a running thread. This is a big problem if we want to delete thread in function of thread destructor ( via new thread created in destructor). See also bug 1.

The thread will be put into the EXIT state and be woken up (although in 
your case it already is, but the point is that its state will then be 
cleared of SLEEPING) and if you check the return value of cyg_thread_delete 
^^^^^^^^^^^^^^^^^^ state of the thread to be killed already been RUNNING but *sleep_reason was not NONE*
the code is:

   if ( EXIT != wake_reason ) switch( sleep_reason ) {
        // Only do any of this if the thread is not in pending death already:

    case NONE:
        // The thread is not sleeping for any reason, it must be
        // on a run queue.
        // We can safely deschedule and set its state.
        if( state == RUNNING ) Cyg_Scheduler::scheduler.rem_thread(this);
        state = EXITED;
        break;
        
    case DESTRUCT:
    case BREAK:
....................
................
if we are calling kill() to kill RUNNING thread (*but it's sleep_reason!=NONE*), then thread will not be killed immediately, although it must be. It will be killed only after second kill().



> 3. 
> see "packages\kernel\current\src\common\thread.cxx"
> 
> Cyg_Thread::kill().
> 
> Try to kill thread that in RUNNING state, will not invoke thread destructors whereas destructors calling in Cyg_Thread::exit(), but kill() invoke exit() only if thread was in SLEEPING state ( via "wake_reason=EXIT")

Hmm... I'm not decided about this one. It's true the behaviour isn't very 
symmetric, but loosely part of the point is that a kill is very much 
*forcing* a thread to exit. As the comment about Cyg_Thread::kill says:
...........
.........
If you would care to propose a simple deterministic solution then I'm sure 
we'd consider it.

Why we can't invoke destructors in kill() function, before dropping it to EXITED ?
At present time there's no way to kill thread (from another) in ensurance that destructors will be called.
( I mean "kapi.h" functions ) And it is very wrong.

With best regards, Anton Kondratenko.



--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]