mutex.c
来自「xenomai 很好的linux实时补丁」· C语言 代码 · 共 34 行
C
34 行
#include <native/mutex.h>RT_MUTEX mutex_desc;int main (int argc, char *argv[]){ int err; /* Create a mutex; we could also have attempted to bind to some pre-existing object, using rt_mutex_bind() and rt_mutex_bind() instead of creating it. In any case, priority inheritance is automatically enforced for mutual exclusion locks. */ err = rt_mutex_create(&mutex_desc,"MyMutex"); /* Now, grab the mutex lock, run the critical section, then release the lock: */ rt_mutex_lock(&mutex_desc,TM_INFINITE); /* ... Critical section ... */ rt_mutex_unlock(&mutex_desc); /* ... */}void cleanup (void){ rt_mutex_delete(&mutex_desc);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?