Changing task mode

Joel Sherrill joel.sherrill at
Fri Aug 14 11:56:46 UTC 2009

Leonard Bise wrote:
> Hi all,
> I have a task performing some actions, that I would like to not be 
> done at the same time by another task. I know it would certainly be 
> better to use semaphores but this code was not writtten by me and it 
> would be complicated to change it.
> To do so I chose to modify the task mode of my current task executing 
> the actions that should not be done concuratively like so.
> rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &previous_mode);
> If I understand it correctly this new mode should keep other tasks 
> from being called until I reactivate the preemption, is it correct?
> So for the time where my current task is set as not preemptive I have 
> no risk that the code I'm currently executing will be done by another 
> task.
Yes.  If a higher priority task becomes ready while this task is in
a NO_PREEMPT mode, it will NOT be preempted and will continue
to run until it changes more or yields.  If you block naturally, another
task will run though.
> I hope someone can clarify this for me.
> Thanks in advance, Léo.

More information about the users mailing list