-
-
Notifications
You must be signed in to change notification settings - Fork 39.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] defer_exec is deleted by created by another deferred task (that has to delete itself) #22697
Comments
The I might be missing some "weird" use case here, but on first sight the only scenario where i can see this (freeing the slot before the |
I totally agree, you usually don't need to cancel deferred task within itself. But in case where it cancels itself, I can't create a new deferred task. Well, I have already got a workaround, I can defer task first and than cancel, and that works.
But anyway, it seems to be a bug there |
IMO it would be much better to use
Yeah, this would work... Unless, as said on my other message (sorry i edited it a couple times), you are already at the maximum of concurrent task, and
I'm not the designer of the API, but to my eye it sounds more like a limitation/un-intended usage than a bug. I cant (didn't spend much time on it, mind you) think of a clean way to detect the "cancelled the task and created a new one on the same slot during its callback" scenario. The best idea i can think of right now would be to have some sort of "admin" task whose ...But that sounds like quite an overkill vs simply increasing the number of executors you can have running at the same time, and forget about cancelling them from within themselves (doing it with the EDIT: Im aware both of my proposals would still be problematic... "Admin" task may get its own token to be cancelled if you aren't careful, and the second one wouldn't have a clean way to cancel a task from another taks (but you can maybe handle that elsewhere) |
I'm not sure if it make sense for you, I don't know a codestyle of this project and best practices in C. But for me it seems reasonable to check if entry's state was changenged right after callback finished. And in case if state has changes just ignore other post-callback actions. So, code would be something like this:
Does that make any sense? That would fix both your case with reaching limits and my. |
It makes sense, but it can still run into the same issue (less likely, tho)
|
See if #22722 fixes matters. |
Describe the Bug
Here is my case.
I create a deferred task, that cancels itself (I know, it's not necessary, but in runtime there could be other tasks to cancel. So sometimes it has to cancel itself). If I put creation another deferred task after cancelation, it would be deleted. Let me show a code:
In that case some_task will be called in 1000ms, but another_task wouldn't be started in 2000.
I believe a bug lives in deferred_exec.c in function deferred_exec_advanced_task
It holds a pointer to entry and executes callback:
entry->callback(entry->trigger_time, entry->cb_arg);
If you will call cancel_deferred_exec within that callback, it will erase current entry's state.
And a new callback to another_task will be written in that entry.
So, after exiting entry->callback deferred_exec_advanced_task will erase current entry's state again.
Keyboard Used
any
Link to product page (if applicable)
No response
Operating System
No response
qmk doctor Output
No response
Is AutoHotKey / Karabiner installed
Other keyboard-related software installed
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: