#4435 closed defect (fixed)

Thread cancellation may produce ready threads with an active thread timer

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 6.1
Component: score Version: 6
Severity: normal Keywords: qualification
Cc: Blocked By:
Blocking:

Description

The _Thread_Cancel() (in contrast to _Thread_Restart() which uses a similar code block) may produce ready threads with an active timer in case the thread to cancel has its thread life protection enabled. The problem is this code block:

    Priority_Control priority;

    _Thread_Add_life_change_request( the_thread );

    if ( _Thread_Is_life_change_allowed( previous ) ) {
      _Thread_State_release( the_thread, &lock_context );

      _Thread_queue_Extract_with_proxy( the_thread );
      _Thread_Timer_remove( the_thread );
    } else {
      _Thread_Clear_state_locked( the_thread, STATES_SUSPENDED );
      _Thread_State_release( the_thread, &lock_context );
    }

    priority = _Thread_Get_priority( executing );
    _Thread_Raise_real_priority( the_thread, priority );
    _Thread_Remove_life_change_request( the_thread );

The life change request should only be added/removed if a life change is allowed (see _Thread_Restart()).

Change History (2)

comment:1 Changed on 05/26/21 at 12:41:24 by Sebastian Huber <sebastian.huber@…>

Resolution: fixed
Status: assignedclosed

In ce6319a/rtems:

score: Fix _Thread_Cancel()

The _Thread_Cancel() (in contrast to _Thread_Restart() which used a
similar code block) may have produced ready threads with an active timer
in case the thread to cancel had its thread life protection enabled. The
problem was this code block:

Priority_Control priority;

_Thread_Add_life_change_request( the_thread );

if ( _Thread_Is_life_change_allowed( previous ) ) {

_Thread_State_release( the_thread, &lock_context );

_Thread_queue_Extract_with_proxy( the_thread );
_Thread_Timer_remove( the_thread );

} else {

_Thread_Clear_state_locked( the_thread, STATES_SUSPENDED );
_Thread_State_release( the_thread, &lock_context );

}

priority = _Thread_Get_priority( executing );
_Thread_Raise_real_priority( the_thread, priority );
_Thread_Remove_life_change_request( the_thread );

The life change request should only be added/removed if a life change is
allowed (see _Thread_Restart()). Add _Thread_Try_life_change_request()
and use it in _Thread_Cancel() and _Thread_Restart().

Close #4435.

comment:2 Changed on 06/23/21 at 07:07:55 by Sebastian Huber

Keywords: qualification added
Note: See TracTickets for help on using tickets.