Page 1 of 1

priority order violation when calling chSysUnlock from virtual timer callback

Posted: Tue Oct 10, 2017 8:04 am
by sidbh
Hi,
I am trying to do a mutex lock inside the virtual timer callback set using chVTSet method. But I see that from the chSysUnlock i.e. called from while being inside the callback for mutex lock leads to debug error, Priority order violation. the value of ch.rlist.current is idle_thread context and the value of next is the thread which I created from which the chVTSet was called and has priority of 181. I am trying to understand is it illegal to do locks inside virtual timer callbacks, which doesn't seem so from example codes as you are calling function which do critical sections from the callbacks. So why I am having this issue.

Regards,
Siddharth

Re: priority order violation when calling chSysUnlock from virtual timer callback

Posted: Tue Oct 10, 2017 9:02 am
by Giovanni
Hi,

It is illegal to do in callbacks/ISRs anything that can change the state of the current thread. In general, from callbacks/ISRs you can only call I-Class functions, those whose name is ended by "I".

The state checker, which you should enable, detects this kind of violations.

Giovanni