# Proposal: optional preemption-threshold scheduling

**URL:** <https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188>\
**Category:** Kernel\
**Created:** [October 12, 2026, 6:45am UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188 "2026-10-12T06:45:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vansvan17](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/vansvan17/32/6456_2.png) [@vansvan17](https://forums.freertos.org/u/vansvan17)\
**Post date:** [October 12, 2026, 6:45am UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/1 "2026-10-12T06:45:49Z")

</div>

I would like feedback on adding optional preemption-threshold scheduling to the FreeRTOS kernel.

## Motivation

FreeRTOS currently supports preemptive and cooperative scheduling. A preemption threshold provides an intermediate model for fixed-priority tasks. Each task has its normal priority P and an optional threshold T, where T is at least P. While the task runs, another task may preempt it only if the other task’s priority is greater than T. The running task still relinquishes the processor normally when it blocks, suspends, or yields.

This can reduce context switches and bound selected non-preemptive regions without disabling all preemption. A sufficiently urgent task can still preempt a threshold-protected task.

## Proposed interface

The feature would be disabled by default using a configuration option. When enabled, a task’s threshold would initially equal its priority, preserving existing scheduling behavior until the application explicitly raises it.

The initial prototype used these APIs:

```c
void vTaskPreemptionThresholdSet( TaskHandle_t xTask,
                                  UBaseType_t uxNewThreshold );

UBaseType_t uxTaskPreemptionThresholdGet( TaskHandle_t xTask );

```

For example, a task with priority 3 and threshold 4 cannot be preempted by a priority-4 task, but a priority-5 task can preempt it.

## Questions

1. Is preemption-threshold scheduling a feature the project would consider?
2. Should the initial implementation support only single-core scheduling, or must it include SMP semantics in the first contribution?
3. Would maintainers prefer a task-creation parameter, setter and getter APIs, or a different interface?
4. How should a threshold interact with inherited priority and runtime priority changes?
5. Should equal-priority time slicing remain independent of the threshold?

## Implementation and validation plan

I have a proof of concept against an older FreeRTOS kernel copy, but I will not submit that patch directly. If the feature is considered suitable, I will implement it against the current FreeRTOS-Kernel main branch and include CMock unit tests covering task creation, wakeups, notifications, event-list removal, runtime priority changes, static allocation, and unchanged behavior when the feature is disabled.

I would appreciate guidance on the desired semantics and scope before opening a kernel pull request.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [October 12, 2026, 6:49am UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/2 "2026-10-12T06:49:51Z")

</div>

We do provide an API to alter a task’s priority at runtime: [FreeRTOS-Kernel/include/task.h at main · FreeRTOS/FreeRTOS-Kernel · GitHub](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/include/task.h#L1263).

Would you please elaborate on what problem this proposal solves and how it is not solved by dynamically changing priority?

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [October 12, 2026, 7:16am UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/3 "2026-10-12T07:16:55Z")

</div>

I don’t think that this is a useful feature. Among other things, it introduces obfuscated unexpected behavior. Consider the following use case:

- A pre-build library or a third party code set such as a HAL uses the feature, allowing only tasks of priority T to preempt its internally operating task(s).
- An application encounters the situation where one of its tasks runs at a priority \< T and thus does not meet its expected deadlines but does at the moment its priority is raised \> T.

Of course, it can be argued that the same scenario applies to the same libaries/middleware using the legacy API, which is yet another argument to use dynamic priority adjustment only very cautiously, explicitly and sparsely.

Can you sketch a use case in which you think that your feature could be useful?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [October 12, 2026, 1:25pm UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/4 "2026-10-12T13:25:08Z")

</div>

> [@vansvan17](#):
>
> 1. Is preemption-threshold scheduling a feature the project would consider?
> 2. Should the initial implementation support only single-core scheduling, or must it include SMP semantics in the first contribution?
> 3. Would maintainers prefer a task-creation parameter, setter and getter APIs, or a different interface?
> 4. How should a threshold interact with inherited priority and runtime priority changes?
> 5. Should equal-priority time slicing remain independent of the threshold?
> 
> ## I

1. I can’t speak for the team, but such a feature will make it much harder to reason/prove timing requirements. I will comment on a few things that I see with this.

2. While single-core might be a reasonable proof-of-concept, if the methodology can’t extend to SMP, it would be severely limited. It shouldn’t be hard to define it for SMP, as you just define that a given core won’t give up its task unless it is switching to a task above the current task threshold.

3. First thought is that since most of the API is based on setter/getter API, that would be the more common.

4. inherited priority MUST still work, so should run-time changes in priority. I would expect that if a task’s current priority (even if inherited) is above its threshold should act as at least that high (you probably need an extra field to handle inherited thresholds). Raising a priority above the threshold should raise the threshold (effective threshold should never be below effective priority). Dropping priority would be a question, perhaps the base function drops the threshold too, and you have a second function do adjust both together).

5. This feature seems at odds with round-robin scheduling. You might be able to work a specification where there is a way to specify not being able to be preempted by a same priority task by the round-robin scheduler.

I would say one big issue to take care of is that if a task with a raised threshold IS preempted by a task above its threshold, when that task switches out, by the rules, a task above that task but below its threshold would still be eligible to run. If you don’t want that, then you should have just raised your base priority. This means your “non-preemptive regions” don’t actually exist.

An example:  
Task A, Priority 3, threshold 4 is running  
Task B, Priority 4 becomes ready, but is held off by the threshold  
Task C, Priority 5 becomes ready, and is switched to because it is above the preemption threshold  
Task C reaches a blocking point.  
The highest ready task is B, as task A threshold of 4 doesn’t apply if it isn’t running.  
Thus, Task A can not assume that B will not run in the thresholded area.  
If it needed to make that assumption valid, it should have just changed its priority to 4.

What might be a useful addition is something to better control when switching out a task if it goes to the front or back of its current priority queue.

---

<div class="post-metadata">

**Author:** ![vansvan17](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/vansvan17/32/6456_2.png) [@vansvan17](https://forums.freertos.org/u/vansvan17)\
**Post date:** [October 13, 2026, 11:59am UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/5 "2026-10-13T11:59:04Z")

</div>

Thanks, these are fair questions.

The distinction I am trying to explore is that dynamically changing a task’s priority changes its ordering against all ready tasks and can interact with priority inheritance. A preemption threshold leaves the base priority unchanged and only constrains whether a newly ready task may preempt the current execution. It represents a bounded non-preemptive region while retaining an escape path for genuinely urgent work.

A concrete use case is a periodic control task that reads sensor state, performs a short bounded estimator or controller update, and publishes an actuator command. Suppose the compute phase takes 50 to 100 microseconds and has a hot working set. Medium-priority telemetry or logging tasks that become ready during this phase can introduce several context switches and cache disruption, increasing completion-time jitter. Making the region completely non-preemptive would also delay a high-priority fault-handling task. A threshold could defer the medium-priority work while still allowing the fault handler to preempt. Once the control task blocks, yields, or leaves the region, normal scheduling resumes.

I agree that hidden use by a library or HAL would be dangerous. I would not propose allowing middleware to silently impose thresholds. The feature should be disabled by default, used explicitly at the application scheduling boundary, and exposed through trace facilities. A scoped enter and exit interface may be safer than a persistent task property.

To determine whether this is actually useful, I can build a benchmark comparing normal fixed-priority scheduling, explicit priority raise and restore with vTaskPrioritySet(), scheduler suspension or a critical-section alternative, and a threshold implementation. I would measure context-switch count, control-task completion jitter, worst-case response of the urgent task, and interactions with priority inheritance. If the threshold does not provide a measurable or semantic advantage, that would be evidence against adding it.

Would this benchmark and scoped use case be a useful basis for evaluating the proposal?

Richard, your example also shows that my use of the phrase non-preemptive region was too strong. The threshold only constrains direct preemption while task A is running. If a higher-priority task C preempts A and then blocks, task B may run before A resumes. I would not treat the threshold as mutual exclusion or as a guarantee that B cannot execute until A finishes. If an application needs that guarantee, raising the base priority or using synchronization is the correct mechanism. I would include this nested-preemption case in the benchmark and specification.

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [October 13, 2026, 12:21pm UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/6 "2026-10-13T12:21:10Z")

</div>

> [@vansvan17](#):
>
> The distinction I am trying to explore is that dynamically changing a task’s priority changes its ordering against all ready tasks and can interact with priority inheritance. A preemption threshold leaves the base priority unchanged and only constrains whether a newly ready task may preempt the current execution. It represents a bounded non-preemptive region while retaining an escape path for genuinely urgent work.

Would a priority ceiling implementation serve the same purpose?

> [@vansvan17](#):
>
> A concrete use case is a periodic control task that reads sensor state, performs a short bounded estimator or controller update, and publishes an actuator command. Suppose the compute phase takes 50 to 100 microseconds and has a hot working set. Medium-priority telemetry or logging tasks that become ready during this phase can introduce several context switches and cache disruption, increasing completion-time jitter. Making the region completely non-preemptive would also delay a high-priority fault-handling task. A threshold could defer the medium-priority work while still allowing the fault handler to preempt. Once the control task blocks, yields, or leaves the region, normal scheduling resumes.

As @aggarg already pointed out, the existing dynamic priority modification API could prefectly handle this case. I don’t like either approach very much and believe that there are better ways to solve this problem, but your extensions would make the “hidden threshold priority” the default which means that unless the coder explicitly disables (revokes) the threshold when unneeded, your tasks would by default always claim an obfuscated priority. In my book, it is less bad to explicitly require the designers to enforce the unexpected behavior than allow them to forget to disable it.

> [@vansvan17](#):
>
> I agree that hidden use by a library or HAL would be dangerous. I would not propose allowing middleware to silently impose thresholds. The feature should be disabled by default, used explicitly at the application scheduling boundary, and exposed through trace facilities. A scoped enter and exit interface may be safer than a persistent task property.

I do not see a way to enforce this logistically because there is no way to distinguish middleware from application software; also, IF middleware decided to use such a feature, it would do so with some rationale, so if client software was able to disable that feature, then the middleware will behave unexpectedly which opens up all maintenance hell. I have seen a number of cases in which many thousands of hours were spent trying to pinpoint issues stemming from such well intended but error prone features.

I am not in charge of approving PRs, but if that feature was submitted as a PR and I had a say, I would reject it or delegate to an unsupported/experimental third party submitted code section. The crux with all such ideas is that if they make it into the official code base, somebody will use them and require support and maintenace if they expose weaknesses or problems.

Thanks for the effort and the offer to contribute your code, though!

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [October 13, 2026, 1:46pm UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/7 "2026-10-13T13:46:11Z")

</div>

I would say that your sensor task SHOULD be higher (or at least the same) in priority than the telemetry and logging tasks that you are worried would interfere with it. In my mind “logging” is normally a very low priority task, as there is little care about when it finishes, as long as it does, while “control” is a moderate to high priority. True “Faults” are often handled in ISR, but might need to transfer to a top priority task.

Also, a task raising its own priority will not cause it to lose the processor, so even if it raises its priority as it reads the sensor so it will not be delayed by other operations is a viable method.

Your example makes it sound more like you are trying to fix poorly set priorities with a complication rather than doing the work to set priorities correctly.

Remember, “Priority” is the knob to control how urgent an operation is considered, not necessarily how “important” it is.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [October 15, 2026, 7:23am UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/8 "2026-10-15T07:23:01Z")

</div>

> [@vansvan17](#):
>
> A concrete use case is a periodic control task that reads sensor state, performs a short bounded estimator or controller update, and publishes an actuator command. Suppose the compute phase takes 50 to 100 microseconds and has a hot working set. Medium-priority telemetry or logging tasks that become ready during this phase can introduce several context switches and cache disruption, increasing completion-time jitter. Making the region completely non-preemptive would also delay a high-priority fault-handling task. A threshold could defer the medium-priority work while still allowing the fault handler to preempt. Once the control task blocks, yields, or leaves the region, normal scheduling resumes.

Let’s say you have the following priorities (the actual numbers are not important, but the relative ordering is):

```auto
Fault handling task = 3 [High]
Control task = 2 [Medium]
Logging task = 1 [Low]

```

Would this not achieve what you are trying to achieve?

---

<div class="post-metadata">

**Author:** ![vansvan17](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/vansvan17/32/6456_2.png) [@vansvan17](https://forums.freertos.org/u/vansvan17)\
**Post date:** [October 18, 2026, 3:09pm UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/9 "2026-10-18T15:09:59Z")

</div>

Yes, with the priorities in your example, normal fixed-priority scheduling would achieve the intended ordering, so my example did not establish a need for a threshold.

The case I intended is one where the interfering task requires a higher base priority because of its own period or relative deadline. For example, the fault task has priority 3, telemetry has priority 2, and control has priority 1. The controller’s threshold is temporarily 2 during a short bounded compute section. Telemetry retains its higher base priority globally, but is deferred during that section, while the fault task can still preempt.

That said, an explicit temporary priority raise may provide the same effective ordering. I am therefore treating this as a comparison question rather than assuming a new mechanism is necessary. I have implemented benchmark modes for normal fixed-priority scheduling, priority raise and restore, preemption threshold, and scheduler suspension. If the threshold does not provide a measurable or semantic advantage, I agree that it should not be added to the kernel.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [October 18, 2026, 4:56pm UTC](https://forums.freertos.org/t/proposal-optional-preemption-threshold-scheduling/25188/10 "2026-10-18T16:56:38Z")

</div>

The problem is I don’t think you CAN create the case you want, as BY DEFINITION if the “lower priority” task with the threshold is ok to delay what you want to make the mid-priority task, that tasks deadlines CAN’T be greater than that first task, and thus SHOULD have had a lower priority in the first place.

Note, it seems you have a fundamental problem by thinking that “period” has any direct aspect in determining priority. The classic arguement to do that is based on the concept that tasks often have their whole period to do their operation, and thus period can be a standin for deadline.

The whole impetus for your method is to make the lower priority be able to try to meet a tighter deadline than the middle priority task. And, it doesn’t work as was pointed out that a high-priority task breaks the condition you were trying to maintain, and the task trying to use the threshold actually can miss its deadline.

Your threshold concept adds significant complexity to the system (as it needs to also integrate with priority-inheritance, and thus you also may need such inheritance for the threshold).

So, unless you can show a real case that would need this method, it seems to be an anti-pattern.

As you just admitted, your example doesn’t show a need. Can you come up with one that does, or is this just a complicated answer looking for a problem? Remember, you have a fundamental issue that an above-threshold task coming in blocks the task using the threshold, and makes it suffer the delays that your method was designed to avoid, as the mid-priority task will take over.

Maybe there are some “soft” improvements due to cache improvements in the “hot” section. But Real-Time systems tend to be designed to meet “hard” real-time requirements, which this method seems to make harder to evaluate, or even test, as you are introducing more corner cases with bigger impact that need to be tested.
