×
嵌入式 > 技术百科 > 详情

MSP430实现简单的对临界资源的冲突访问

发布时间:2020-06-01 发布时间:
|

实现对临界资源的冲突访问


__monitor int get_lock(void)
{
if (the_lock == 0)
 {
  /* Success, we managed to lock the lock. */
  the_lock = 1;
  return 1;
 }

else
 {
  /* Failure, someone else has locked the lock. */
  return 0;
  }
 }


/* release_lock -- Unlock the lock. */
 __monitor void release_lock(void)
 {
  the_lock = 0;
  }


void my_program(void)
 {
 if (get_lock())
  {
    /* ... Do something ... */
    /* When done, release the lock. */
   release_lock();
  }
}


 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
ADI 高精度低功耗精密放大器