You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering, what measures I have to take to really ensure atomicity on an operation. On a single core without multithreading I would have to irq_lock() my critical section. With the possibility of multi core I (and for good practice anyways) I would use k_spin_lock() instead. If I have preemtive threads with timeslicing, k_sched_lock() can ensure my thread is not preempted while in the critical section. But how far do I have to go for SMP + preemtive? Do I need to combine k_spin_lock() and k_sched_lock(), or does k_spin_lock() implicitly prevent timeslicing?
My guess would be, that timeslicing is internally based on interrupts, and thus with interrupts disabled through k_spin_lock() no timeslicing would take place. Also, from a contract point of view, it would be a weakness of k_spin_lock() to not protect against timeslicing.
But I could not find any documentation adressing this question, neither in the threading / multithreading sections nor in the scheduling sections. So for my peace of mind, I would like to ask you to confirm my intuition - or teach me how it is done :)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I was wondering, what measures I have to take to really ensure atomicity on an operation. On a single core without multithreading I would have to
irq_lock()
my critical section. With the possibility of multi core I (and for good practice anyways) I would usek_spin_lock()
instead. If I have preemtive threads with timeslicing,k_sched_lock()
can ensure my thread is not preempted while in the critical section. But how far do I have to go for SMP + preemtive? Do I need to combinek_spin_lock()
andk_sched_lock()
, or doesk_spin_lock()
implicitly prevent timeslicing?My guess would be, that timeslicing is internally based on interrupts, and thus with interrupts disabled through
k_spin_lock()
no timeslicing would take place. Also, from a contract point of view, it would be a weakness ofk_spin_lock()
to not protect against timeslicing.But I could not find any documentation adressing this question, neither in the threading / multithreading sections nor in the scheduling sections. So for my peace of mind, I would like to ask you to confirm my intuition - or teach me how it is done :)
Beta Was this translation helpful? Give feedback.
All reactions