if(g_quit) break; // 如果程序需要退出,则终止循环
// 等待用户的许可的信号,如果没有收到信号,则等待
pthread_cond_wait(&g_cond, &g_mutex);
key = g_key;
pthread_mutex_unlock(&g_mutex);
if(key != -1)
{
// do some work
// 例如:
if(( key >= 0x30 && key <= 0x39) // '1' ~ '9'
|| (key >= 0x41 && key <= 0x5A) // 'A' ~ 'Z'
|| (key >= 0x61 && key <= 0x7A) // 'a' ~ 'z'
)
{
printf("control key = %c\n", (char)key);
}else
printf("control keycode = %d\n", key);
sleep(1); // 假设完成工作需要耗时1秒
}
}
pthread_mutex_unlock(&g_mutex);
printf("camera_control_thread exit...\n");
pthread_exit(NULL);
}
上一页 [1] [2]