cond_var.c
来自「xenomai 很好的linux实时补丁」· C语言 代码 · 共 57 行
C
57 行
#include <native/mutex.h>#include <native/cond.h>RT_COND cond_desc;RT_MUTEX mutex_desc;int shared_event = 0;void foo (void){ int err; /* Create a condition variable and a mutex guarding it; we could also have attempted to bind to some pre-existing objects, using rt_cond_bind() and rt_mutex_bind() instead of creating them. */ err = rt_mutex_create(&mutex_desc,"MyCondMutex"); err = rt_cond_create(&cond_desc,"MyCondVar"); /* Now, wait for some task to post the shared event... */ rt_mutex_lock(&mutex_desc,TM_INFINITE); while (!shared_event && !err) err = rt_cond_wait(&cond_desc,&mutex_desc,TM_INFINITE); rt_mutex_unlock(&mutex_desc); /* ... */}void bar (void){ /* ... */ /* Post the shared event. */ rt_mutex_lock(&mutex_desc,TM_INFINITE); shared_event = 1; rt_cond_signal(&cond_desc); rt_mutex_unlock(&mutex_desc); /* ... */}void cleanup (void){ rt_cond_delete(&cond_desc); rt_mutex_delete(&mutex_desc);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?