how to make sure an operation is atomic?

4 posts / 0 new
Last post
achao1104
Offline
Last seen:5 years 2 months ago
Master
加入:2015-12-24 10:56
how to make sure an operation is atomic?

Hi,
In sdk5, I use interrupt to wake up device, but the waking up interrupt may be fired in very high frequency, how to avoid problems due to concurrent running?

in callback function, I coded as below, but it doesn't work, I think the "=" operation is not atomic.

if(is_working==0)
{
is_working=1;
...

}

Device:
MT_dialog
Offline
Last seen:1 month 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi achao,

Hi achao,

I am not sure i understand the question, you want to know how you can prevent an other interrupt executing while the previous one is executed ? can you please give some more details about what you want to do ?

Thanks MT_dialog

achao1104
Offline
Last seen:5 years 2 months ago
Master
加入:2015-12-24 10:56
我让设备进入

我让设备进入deep sleep, while allowing interrupt to wake up it. the interrupt might happen in very high frequency, say there are 20 interrupts at almost the same time. thus, the wake up callback will be called almost 20 times in a very short time.
in above case, I want to only allow one execution of the call back (for the first interrupt, that is why set is_working=1), thus, the second and afters will be prevented and return directly.
by testing, I observed there are still multiple executions of the call back, that is why I am thinking the reason might be due to above codes are not atomic.

MT_dialog
Offline
Last seen:1 month 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi achao1104,

Hi achao1104,

Try to disable the wakeup interrupt after call of the ISR happens at the first time. The "=" is not atomic, the assembly command that is being executed maybe is but your code has more that one assembly commands that can be interrupted by an ISR call.

Thanks MT_dialog