Replies: 3 comments 7 replies
-
Circle provides functions for the atomic access to int variables (in <circle/
atomic.h>) and spin locks (in <circle/spinlock.h>) for synchronization. You
can also disable the interrupt (using EnterCritical(), in <circle/
synchronize.h>), but this is normally not recommended, because it only works
with single-core applications. If one uses tasks, there are more possible
synchronization objects.
It depends on the structure of your data and the operations, that you want to
do with it, when you want to decide, which synchronization method to use.
Sometimes you do not need one of these methods (e.g. when a boolean flag is
only set from the interrupt handler and read from the main loop), but you
should declare it as "volatile", because the compiler may generate code
otherwise, which reads the variable only once from the main loop and will not
see, when the interrupt handler sets the flag later.
I would need more information about your data and the operations on it, if you
need more info.
|
Beta Was this translation helpful? Give feedback.
6 replies
-
Thank you so much! I just learned there is |
Beta Was this translation helpful? Give feedback.
0 replies
-
I suggest to use always spin locks, so you are sure if you move to multi-core.
In fact CSpinLock::Acquire() degrades to EnterCritical(), if
ARM_ALLOW_MULTI_CORE is not defined. Thus there is no real difference in using
EnterCritical() directly.
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
dirkarnez
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
May i ask is there a safe way / practice to read shared
variable
? It seems Circle has some built-in ways (read locksCSemaphore
orCMutex
or others?) Pseudocode:I did this and i get
EXCEPTION_SYNCHRONOUS
. Thank you so much!Beta Was this translation helpful? Give feedback.
All reactions