李国帅 2018/1/23
在Darwin StreamServer中都是通过atomic操作task的状态,判断是否需要关闭。
#include "OS.h" #include "atomic.h" int main(int argc, char* argv[]) { unsigned int fNumOutputs = 0;// 0xFFFFFF00; (void)atomic_add(&fNumOutputs, 1); if (0 == atomic_sub(&fNumOutputs, 1)) { qtss_printf("atomic value: 0\n"); } int oldEvents = atomic_or(&fNumOutputs, 1);//或 if (compare_and_store(0x1, 0x10, &fNumOutputs)) {//如果两数相等,设置新值,并且返回1,不相等返回0 qtss_printf("atomic value: %x\n", 0x10); } }