📄 cond_var.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -