#609 closed defect (fixed)

Race condition between _Thread_Dispatch and _Thread_Tickle_timeslice

Reported by: Thomas Rauscher Owned by: Joel Sherrill
Priority: normal Milestone: 2
Component: score Version: 4.6
Severity: major Keywords:
Cc: bugs@… Blocked By:
Blocking:

Description

A task is using the classic RTEMS API. The thread control structure is called my_thread in advance.

my_thread->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE
my_thread->cpu_time_budget == 0 (or even uninitialized, I'm not sure)

is true at the beginning.

Now the task is started and rtems_task_create invokes _Thread_Dispatch.

threaddispatch.c

...
_ISR_Disable( level );
while ( _Context_Switch_necessary == TRUE ) {

heir = _Thread_Heir;
_Thread_Dispatch_disable_level = 1;
_Context_Switch_necessary = FALSE;
_Thread_Executing = heir;
executing->rtems_ada_self = rtems_ada_self;
rtems_ada_self = heir->rtems_ada_self;
_ISR_Enable( level );
...

At this point, interrupts are enabled again and a tick interrupt occurs
calling _Thread_Tickle_timeslice. _Thread_Executing is my_thread now.

threadtickletimeslice.c:

...
executing = _Thread_Executing;
...
case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:

if ( --executing->cpu_time_budget == 0 ) {

_Thread_Reset_timeslice();
executing->cpu_time_budget = _Thread_Ticks_per_timeslice;

}
break;

...

Now, thread->cpu_time_budget == 0xFFFFFFFF which means that
the task won't stop until it preempts itself or its timeslice
is exhausted (approx. 49 days using a 1 ms tick).

Release:
RTEMS-4.6

Attachments (1)

threaddispatch.c.diff (678 bytes) - added by Thomas Rauscher on Dec 3, 2006 at 1:31:13 PM.
threaddispatch.c.diff

Download all attachments as: .zip

Change History (2)

comment:1 Changed on Jul 25, 2004 at 2:00:09 PM by Joel Sherrill

Status: assignedclosed

State-Changed-From-To: open->closed
State-Changed-Why: Attached patch applied to trunk and 4.6 branch.

Changed on Dec 3, 2006 at 1:31:13 PM by Thomas Rauscher

Attachment: threaddispatch.c.diff added

threaddispatch.c.diff

Note: See TracTickets for help on using tickets.