data synchronization without using semapore in C

后端 未结 3 714
甜味超标
甜味超标 2021-01-16 03:13

I need to have data synchronization in my code. Currently I am accessing a global value inside interrupt and also in a local function which may corrupt the data if interrup

3条回答
  •  一生所求
    2021-01-16 03:56

    It's probably as simple as this in your main code:

    disable_interrupts();
    value += 1;
    enable_interrupts();
    

    So you make sure the interrupt cannot fire while you're using the value in the main code.

提交回复
热议问题