Events may never be executed if Scheduler::cancelCallback() is used
- Dominant language
- C++
- Stars
- 26
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
The bug can be reproduced with the code below:
``` c++
using minar::Scheduler;
void periodic() {
// Just a dummy function
}
void delayedFunction(int id) {
printf("%d ", id);
}
minar::callback_handle_t schedule(uint32_t id)
{
mbed::util::FunctionPointer1 ptr(delayedFunction);
return Scheduler::postCallback(ptr.bind(id))
.delay(minar::milliseconds(id * 50))
.getHandle();
}
void testMinar()
{
minar::callback_handle_t handles[14];
int values[] = { 59, 46, 79, 7, 62, 6, 8, 10, 36, 11, 14, 70, 61, 1 };
// Schedule 14 events with a delay of 50*value ms
for (int i = 0; i < sizeof(values) / sizeof(int); i++) {
handles[i] = schedule(values[i]);
}
// Start a periodic callback - this will prevent the scheduled event for value 7 to execute
// If this line is removed minar will instead assert
Scheduler::postCallback(periodic).period(100);
// Cancel value 11
Scheduler::cancelCallback(handles[9]);
}
```
The code schedules 14 single shot events and 1 periodic "dummy" event. One of the single shot events is canceled and the expected output is:
```
1 6 7 8 10 14 36 46 59 61 62 70 79
```
The actual output looks like this:
```
1 6 8 10 14 36 46 59 61 62 70 79
```
I.e. 7 is never executed.
This bug is actually a result from [mbed::util::BinaryHeap.remove()](https://github.com/ARMmbed/core-util/issues/108), but I think it would be a good idea to have a separate issue in minar for traceability.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided reproduction and trace Scheduler::cancelCallback() through the scheduler's event handling. Then inspect mbed::util::BinaryHeap.remove() and the linked core-util issue. Done means the canceled value 11 remains absent while value 7 executes, producing the expected output without an assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100